-
Notifications
You must be signed in to change notification settings - Fork 1
/
delete_booking.php
48 lines (43 loc) · 1.66 KB
/
delete_booking.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
<?php
// Establish database connection
$servername = "localhost:3307";
$username = "root";
$password = "";
$dbname = "testdb";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Get the ID of the booking to be deleted
$id = $_POST['booking_id'];
// Delete the record from the numofppl table that references the booking to be deleted
$sql = "DELETE FROM numofppl WHERE tour_id=(SELECT tour_id FROM bookings WHERE id=".$id.")";
if ($conn->query($sql) === TRUE) {
// Delete the record from the bookings table
$sql = "DELETE FROM bookings WHERE id=".$id;
if ($conn->query($sql) === TRUE) {
// Get the ID of the tour to be deleted
$result = mysqli_query($conn, "SELECT tour_id FROM bookings WHERE id=".$id);
if ($result && mysqli_num_rows($result) > 0) {
$tour_id = mysqli_fetch_assoc($result)['tour_id'];
// Delete the record from the tours table
$sql = "DELETE FROM tours WHERE id=".$tour_id;
if ($conn->query($sql) === TRUE) {
// Redirect to index.php with success message
header("Location: index.php?delete=success");
} else {
echo "Error deleting tour: " . $conn->error;
}
} else {
// echo"Error getting tour_id: " . $conn->error;
header("Location: newpaidalltours_confirm.php?delete=success");
}
} else {
echo "Error deleting booking: " . $conn->error;
}
} else {
echo "Error deleting numofppl record: " . $conn->error;
}
// Close database connection
$conn->close();
?>