-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete-seat.php
72 lines (69 loc) · 2.49 KB
/
delete-seat.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
session_start();
$pageTitle = 'Delete Your Seats';
include 'init.php';
include $template . 'header.php';
include $template.'navbar.php';
if(!isset($_SESSION['user'])){
header('Location: login.php');
}
$flight_id = $_GET['flight_id'];
$sql = "
SELECT res.seat_id, flight_id, class_type
FROM reservation res
JOIN seat st
ON res.seat_id = st.seat_id
where user_id = {$_SESSION['user']['user_id']} AND res.flight_id = $flight_id
ORDER BY res.seat_id
";
$stmt = $conn->prepare($sql);
$stmt->execute();
$reservations = $stmt->fetchAll(PDO::FETCH_ASSOC);
if(isset($_GET['seat_id'])){
$seat_id = $_GET['seat_id'];
/*
* DELETE Query Syntax
* */
$sql = "DELETE FROM reservation WHERE seat_id = $seat_id";
$stmt = $conn->prepare($sql);
$stmt->execute();
header('Location: delete-seat.php?flight_id='.$_GET['flight_id']);
}
?>
<div class="container my-5">
<h1>My Reserved Seats</h1>
<table class="table table-dark table-striped">
<thead>
<tr>
<th scope="col">Seat ID</th>
<th scope="col">Flight ID</th>
<th scope="col">Seat Class Type</th>
<th scope="col" class="text-center">Controls</th>
</tr>
</thead>
<tbody>
<?php
if(count($reservations) == 0){
echo '<tr><td colspan="4" class="text-center">No Seats</td></tr>';
}else {
foreach ($reservations as $flight) { ?>
<tr>
<td><?= $flight['seat_id'] ?></td>
<th scope="row"><?= $flight['flight_id'] ?></th>
<td><?= $flight['class_type'] ?></td>
<td class="text-center">
<!-- <form action="book-flight.php?flight_id=-->
<?php //echo $flight['flight_id'];
?><!--" method="GET">-->
<form action="delete-seat.php" method="GET">
<input type="hidden" name="flight_id" value="<?= $flight['flight_id'] ?>">
<input type="hidden" name="seat_id" value="<?= $flight['seat_id'] ?>">
<input type="submit" value="Cancel" class="btn btn-danger"/>
</form>
</td>
</tr>
<?php }
}?>
</tbody>
</table>
</div>