-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete_hotel.php
47 lines (40 loc) · 1.45 KB
/
delete_hotel.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
<?php
// Include your database configuration here
$servername = "localhost";
$username = "Atharav";
$password = "Atharav@31";
$dbname = "project";
if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET["id"])) {
// Get the hotel ID from the URL
$hotelId = $_GET["id"];
// Create a database connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Delete records from the 'menus' table that reference the hotel
$sqlDeleteMenus = "DELETE FROM menus WHERE id=?";
$stmtDeleteMenus = $conn->prepare($sqlDeleteMenus);
$stmtDeleteMenus->bind_param("i", $hotelId);
// Use prepared statement to delete the hotel record
$sqlDeleteHotel = "DELETE FROM hotel WHERE id=?";
$stmtDeleteHotel = $conn->prepare($sqlDeleteHotel);
$stmtDeleteHotel->bind_param("i", $hotelId);
// Delete menus first
if ($stmtDeleteMenus->execute()) {
// Then delete the hotel
if ($stmtDeleteHotel->execute()) {
// Redirect back to edit_rest.php with a success message
header("Location: edit_rest.php?delete=success");
exit();
} else {
echo "Error deleting hotel: " . $stmtDeleteHotel->error;
}
} else {
echo "Error deleting menus: " . $stmtDeleteMenus->error;
}
$conn->close();
} else {
echo "Invalid request.";
}
?>