-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd.php
59 lines (56 loc) · 1.83 KB
/
Add.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
<?php
$table = $_GET["table"] ?? null;
require_once "Utility.php";
checkTable($table);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$fields = getColumns($table);
$sql = "INSERT INTO $table (";
foreach ($fields as $key => $field) {
$sql .= $field['name'] . ', ';
}
$sql = substr($sql, 0, -2);
$sql .= ') VALUES (';
$sql .= str_repeat('?, ', count($fields));
$sql = substr($sql, 0, -2);
$sql .= ')';
$params = [];
foreach ($fields as $field) {
array_push($params, $_POST[$field['name']]);
}
$result = bindQuery($sql, $params);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Aggiungi</title>
<?php bootstrap(); ?>
</head>
<body>
<div class="container">
<h1 class="text-center">Aggiungi alla tabella <b><?php echo $table; ?></b></h1>
<form method="POST">
<?php
$fields = getColumns($table);
foreach ($fields as $key => $field) {
$fieldName = $field["name"];
$fieldType = $field["type"];
$fieldType = explode("(", $fieldType)[0];
$fieldType = strtolower($fieldType);
echo "<div class=\"form-group\">
<label for=\"$fieldName\">$fieldName ($fieldType)</label>
<input type=\"$fieldType\" class=\"form-control\" id=\"$fieldName\" name=\"$fieldName\">
</div>";
}
?><br>
<div class="text-center">
<button type="submit" class="btn btn-primary">Aggiungi</button>
</div>
</form>
</div>
<?php overrideBack() ?>
</body>
</html>