66 lines
2.0 KiB
PHP
66 lines
2.0 KiB
PHP
<?php
|
|
include "../../../ConnectDB.php";
|
|
|
|
session_start();
|
|
$uid = mysqli_real_escape_string($conn, $_SESSION['uid']);
|
|
|
|
if (isset($_GET["booking_id"]) && isset($_GET["table"])) {
|
|
$booking_id = mysqli_real_escape_string($conn, $_GET["booking_id"]);
|
|
|
|
switch ($_GET["table"]) {
|
|
case '1':
|
|
$table = "hotel_booking";
|
|
break;
|
|
case '2':
|
|
$table = "restaurant_booking";
|
|
break;
|
|
case '3':
|
|
$table = "attraction_booking";
|
|
break;
|
|
case '4':
|
|
$table = "guide_booking";
|
|
break;
|
|
case '5':
|
|
$table = "transport_flight_booking";
|
|
break;
|
|
case '6':
|
|
$table = "transport_railway_booking";
|
|
break;
|
|
default:
|
|
echo "Unknown booking type";
|
|
}
|
|
|
|
$subtotal_price = "SELECT subtotal_price FROM cart_bookings WHERE booking_id='$booking_id'";
|
|
$res = mysqli_query($conn, $subtotal_price);
|
|
$subtotal_price = mysqli_fetch_assoc($res);
|
|
$subtotal_price = $subtotal_price['subtotal_price'];
|
|
|
|
$quantity_query = "SELECT quantity FROM `$table` WHERE booking_id='$booking_id'";
|
|
$res = mysqli_query($conn, $quantity_query);
|
|
$quantity = mysqli_fetch_assoc($res);
|
|
$quantity = $quantity['quantity'];
|
|
|
|
$delete_query = "DELETE FROM bookings WHERE booking_id='$booking_id'";
|
|
$res = mysqli_query($conn, $delete_query);
|
|
if (!$res) {
|
|
echo "<script type='text/javascript'>
|
|
alert('Error occurred!');
|
|
</script>";
|
|
} else {
|
|
header('Location: ../cart.php'); // Redirect after successful deletion
|
|
}
|
|
|
|
$total = "UPDATE user_buyer SET cart_total_price = cart_total_price - ('$subtotal_price' * '$quantity') WHERE u_id='$uid'";
|
|
$res = mysqli_query($conn, $total);
|
|
if (!$res) {
|
|
echo "<script type='text/javascript'>
|
|
alert('Error occurred!');
|
|
</script>";
|
|
}
|
|
exit();
|
|
} else {
|
|
header('Location: ../cart.php'); // Redirect if booking_id is not set
|
|
exit();
|
|
}
|
|
?>
|