-
Notifications
You must be signed in to change notification settings - Fork 4
/
details.php
50 lines (41 loc) · 1.36 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
<?php
include('../tuto/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)){
header('Location:index.php');
}else {
//error
echo 'query error' . mysqli_error($conn);
}
}
if(isset($_GET['id'])) {
$id = mysqli_real_escape_string($conn, $_GET['id']);
$sql = "SELECT * FROM pizzas WHERE id = $id";
$result = mysqli_query($conn, $sql);
$pizza = mysqli_fetch_assoc($result);
mysqli_free_result($result);
mysqli_close($conn);
}
?>
<!DOCTYPE html>
<html lang="en">
<?php include('templates/header.php')?>
<h2 class="center">Details</h2>
<div class="container center">
<?php if($pizza): ?>
<h4><?php echo htmlspecialchars( $pizza['title']); ?></h4>
<p>created by:<?php echo htmlspecialchars( $pizza['email']); ?></p>
<p>created at:<?php date( $pizza['created_at']); ?></p>
<div><?php echo htmlspecialchars( $pizza['ingredients']); ?></div>
<form action="details.php" method="POST">
<input type="hidden" value="<?php echo $pizza['id'] ?>" name="id_to_delete">
<input type="submit" name="delete" value="Delete" class="btn red z-depth-0">
</form>
<?php else: ?>
<h5 class='red-text'>no pizza here!</h5>
<?php endif; ?>
</div>
<?php include('templates/footer.php')?>
</html>