-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
137 lines (119 loc) · 3.01 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE html>
<html>
<head>
<title>Web Community</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Nunito&display=swap');
</style>
<style>
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
border: 1px solid #e7e7e7;
background-color: #f3f3f3;
}
li {
float: left;
}
li a {
display: block;
color: #666;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #ddd;
}
li a.active {
color: white;
background-color: #04AA6D;
}
table {
border-collapse: collapse;
width: 100%;
}
th, td {
text-align: left;
padding: 8px;
}
tr:nth-child(even){background-color: #f2f2f2}
th {
background-color: #04AA6D;
color: white;
}
</style>
<script src="script.js"></script>
</head>
<body>
<ul>
<li><a href="index.php"class="active" href="">AggiungiEvento</a></li>
<li><a href="search.php">Ricerca Evento</a></li>
<li><a href="">About</a></li>
</ul>
<div class="content">
</div>
<div class="add">
<h1>Aggiungi Evento</h1>
<form action="index.php" method="post" id="formuser">
<label for="titolo">Titolo</label><br>
<input type="text" id="titolo" name="titolo" ><br><br>
<label for="data">Data</label><br>
<input type="date" id="data" name="data"><br><br>
<label for="luogo">Luogo</label><br>
<input type="text" id="luogo" name="luogo"><br><br>
<label for="categoria">Categoria</label><br>
<select name="categoria" id="categoria">
<option value="">Scegli</option>
<option value="concerto">Concerto</option>
<option value="balletto">Balletto</option>
<option value="teatro">Spettacolo teatrale</option>
<option value="mostra">Mostra d'arte</option>
</select><br><br>
<input type="submit" value="Aggiungi" name="add">
</form>
</div>
<?php
if(isset($_POST['add'])){
insertIntoDb();
}
function insertIntoDb(){
$titolo = $_POST['titolo'];
$data = $_POST['data'];
$luogo = $_POST['luogo'];
$categoria = $_POST['categoria'];
$conn = new mysqli("localhost", "root", "", "webcommunity");
//get the category id
$sql = "SELECT idCategoria FROM categorie WHERE descrizione = '$categoria'";
$result = $conn->query($sql);
$row = $result->fetch_assoc();
$id_categoria = $row['idCategoria'];
$sql = "INSERT INTO eventi (titolo, data, luogo,publicatoDa, categoria) VALUES ('$titolo', '$data', '$luogo','ABCDEFG012345678' ,'$id_categoria')";
$conn->query($sql);
$conn->close();
}
function search(){
$conn = new mysqli("localhost", "root", "", "webcommunity");
$sql = "SELECT * FROM eventi";
$result = $conn->query($sql);
echo "<table>";
echo "<tr>";
echo "<th>Titolo</th>";
echo "<th>Data</th>";
echo "<th>Luogo</th>";
echo "<th>Categoria</th>";
echo "</tr>";
while($row = $result->fetch_assoc()){
echo "<tr>";
echo "<td>".$row['titolo']."</td>";
echo "<td>".$row['data']."</td>";
echo "<td>".$row['luogo']."</td>";
echo "<td>".$row['categoria']."</td>";
echo "</tr>";
}
}
?>
</body>
</html>