-
Notifications
You must be signed in to change notification settings - Fork 0
/
details.php
72 lines (48 loc) · 1.82 KB
/
details.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
<?php
// check connection
include('config/db_connect.php');
if(isset($_POST['delete'])){
$id_to_delete = mysqli_real_escape_string($conn, $_POST['id_to_delete']);
$sql = "DELETE FROM pizzas WHERE id = $id_to_delete";
if(mysqli_query($conn, $sql)){
// success
header('Location: index.php');
} else {
// failure
echo 'Query error: ' . mysqli_error($conn);
}
}
// check GET request id parameter
if(isset($_GET['id'])){
$id = mysqli_real_escape_string($conn, $_GET['id']);
$sql = "SELECT * FROM pizzas WHERE id = $id";
// get query results
$result = mysqli_query($conn, $sql);
// fetch result in array format
$pizza = mysqli_fetch_assoc($result);
mysqli_free_result($result);
mysqli_close($conn);
// print_r($pizza);
}
?>
<!DOCTYPE html>
<html>
<?php include 'templates/header.php'; ?>
<div class="container center grey-text">
<?php if($pizza) : ?>
<h4><?php echo htmlspecialchars($pizza['title']); ?></h4>
<p>Added by: <?php echo htmlspecialchars($pizza['email']); ?></p>
<p><?php echo date($pizza['created_at']); ?></p>
<h5>Ingredients:</h5>
<p><?php echo htmlspecialchars($pizza['ingredients']); ?></p>
<!-- DELETE FORM -->
<form action="details.php" method="POST">
<input type="hidden" name="id_to_delete" value="<?php echo $pizza['id']; ?>">
<input type="submit" name="delete" value="Delete" class="btn brand z-depth-0">
</form>
<?php else: ?>
<h5>Error 404: No pizza found!</h5>
<?php endif; ?>
</div>
<?php include 'templates/footer.php'; ?>
</html>