-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsert_data.php
77 lines (66 loc) · 3.17 KB
/
insert_data.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
73
74
75
76
77
<?php
include_once('admin/include/conn.php');
// Retrieve form data
$f_name = $_POST['f_name'];
$l_name = $_POST['l_name'];
$email = $_POST['email'];
$number = $_POST['number'];
$add = $_POST['add'];
$room_type_id = $_POST['roomType'];
$room_no = $_POST['roomNo'];
$max_person = $_POST['max_person'];
// Fetch room information
$fetch_room_info_query = "SELECT rt.price, rt.offers, r.room_id
FROM room_type rt
JOIN room r ON rt.room_type_id = r.room_type_id
WHERE rt.room_type_id = $room_type_id AND r.room_no = '$room_no'";
$result = mysqli_query($conn, $fetch_room_info_query);
if ($result && mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
$price = $row['price']; // Get the price
$room_id = $row['room_id']; // Get the room ID
$offers = $row['offers']; // Get the offers
// Apply offer logic to adjust the total price
if (!empty($offers)) {
$offer_values = explode(",", $offers);
$max_discount = max($offer_values); // Get the maximum discount value
$discounted_price = $price - ($price * ($max_discount / 100)); // Calculate discounted price
$total_price = $discounted_price * $max_person; // Adjust total price with the discounted price
} else {
$total_price = $price * $max_person; // If no offers, use the base price
}
// Check if the email already exists in the customer table
$check_customer_query = "SELECT * FROM customer WHERE email = '$email'";
$check_result = mysqli_query($conn, $check_customer_query);
if ($check_result && mysqli_num_rows($check_result) > 0) {
echo "<script>alert('Customer with this email already exists.');</script>";
} else {
// Insert customer information into the customer table
$insert_customer_query = "INSERT INTO customer (c_name, email, number, `add`)
VALUES ('$f_name $l_name', '$email', '$number', '$add')";
if (mysqli_query($conn, $insert_customer_query)) {
$customer_id = mysqli_insert_id($conn); // Get the ID of the newly inserted customer
// Insert booking information into the booking table
$booking_date = date('Y-m-d'); // Assuming booking date is current date
$check_in_date = $_POST['checkInDate'];
$check_out_date = $_POST['checkOutDates'];
$insert_booking_query = "INSERT INTO booking (customer_id, room_id, booking_date, check_in, check_out, total_price, max_person)
VALUES ($customer_id, $room_id, '$booking_date', '$check_in_date', '$check_out_date', $total_price, $max_person)";
if (mysqli_query($conn, $insert_booking_query)) {
echo "<script>alert('Booking information inserted successfully.');</script>";
?>
<script>
window.location.href="http://localhost/hotel_managment_system1/mybooking.php";
</script>
<?php
} else {
echo "Error inserting booking information: " . mysqli_error($conn);
}
} else {
echo "Error inserting customer: " . mysqli_error($conn);
}
}
} else {
echo "Error fetching room details: " . mysqli_error($conn);
}
?>