-
Notifications
You must be signed in to change notification settings - Fork 2
/
edit_movie.php
88 lines (65 loc) · 1.82 KB
/
edit_movie.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
<?php
$error = $_GET['error'] ?? false;
if ($error) echo "errori di validazione";
$movie_id = $_GET['id'] ?? false;
if (!$movie_id || !is_numeric($movie_id)) {
http_response_code(400);
echo 'INVALID ID PROVIDED IN QUERY STRING';
die();
}
include __DIR__ . '/includes/open_db_conn.php';
$sql = $conn->prepare("SELECT * FROM movies WHERE id = ?");
$sql->bind_param('i', $movie_id);
$sql->execute();
$result = $sql->get_result();
$movie = $result->fetch_assoc();
$query ="SELECT * FROM categories ORDER BY `name` ASC";
$result = $conn->query($query);
if (!$result) {
echo 'Si è verificato un errore';
var_dump($query);
exit();
}
$categories = [];
if ($result && $result->num_rows > 0) {
while ($cat = $result->fetch_assoc()) {
$categories[] = $cat;
}
}
$conn->close();
if (!$movie) {
http_response_code(404);
echo 'Nessun film corrispondente per l\'id fornito';
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php include_once __DIR__ . '/includes/head.inc' ?>
<title>Edit Movie</title>
</head>
<body>
<div class="container p-5">
<header>
<h1>Edit Movie</h1>
</header>
<main>
<form action="update_movie.php" method="POST">
<input type="hidden" name="id" value="<?= $movie['id'] ?>" />
<input type="text" name="title" placeholder="Nome Film" value="<?= $movie['title'] ?>" required />
<select name="category_id" >
<?php foreach ($categories as $cat) { ?>
<option value="<?php echo $cat['id']; ?>"
<?php if ($cat['id'] == $movie['category_id'] ) { ?>
SELECTED
<?php } ?>
><?php echo $cat['name']; ?></option>
<?php } ?>
</select>
<button class="btn btn-primary" type="submit">Aggiungi</button>
</form>
</main>
</div>
</body>
</html>