-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreservationdetails.php
104 lines (86 loc) · 5.05 KB
/
reservationdetails.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Edit Reservation</title>
<link rel="stylesheet" href="styles1.css">
</head>
<body>
<div class="edit-reservation">
<h1>Edit Reservation</h1>
<a href="myreservations.php" >Go Back</a>
<?php
session_start();
include 'db.php'; // Include your database connection
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['edit_reservation'])) {
$_SESSION['reservation_id'] = $_POST['reservation_id'];
$user_id = $_SESSION['user_id']; // Assuming you have stored the user ID in the session
$reservation_id = $_SESSION['reservation_id'];
// Query the specific reservation for the logged-in user
$sql = "SELECT * FROM Reservations
WHERE id_Reservation = '$reservation_id' AND fk_Customerid_User = '$user_id'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$reservation = $result->fetch_assoc();
$room_number = $reservation['fk_Roomroom_number']; // Fetch the room number from the reservation
// Query to get room details including maximum occupancy
$room_query = "SELECT * FROM Rooms WHERE room_number = '$room_number'";
$room_result = $conn->query($room_query);
if ($room_result->num_rows > 0) {
$room_details = $room_result->fetch_assoc();
$maximum_occupancy = $room_details['maximum_occupancy'];
}
// Display the form to edit reservation details
?>
<form action="" method="POST" id="editForm">
<input type="hidden" name="reservation_id" value="<?php echo $reservation['id_Reservation']; ?>">
<label for="guest_name">Customer Name:</label>
<input type="text" id="guest_name" name="guest_name" value="<?php echo $reservation['guest_name']; ?>" readonly><br><br>
<label for="check_in_date">Check-In Date:</label>
<input type="date" id="check_in_date" name="check_in_date" value="<?php echo $reservation['check_in_date']; ?>" min="<?php echo date('Y-m-d'); ?>" required><br><br>
<label for="check_out_date">Check-Out Date:</label>
<input type="date" id="check_out_date" name="check_out_date" value="<?php echo $reservation['check_out_date']; ?>" required><br><br>
<label for="number_of_guests">Number of Guests (Max <?php echo $maximum_occupancy; ?>):</label>
<input type="number" id="number_of_guests" name="number_of_guests" value="<?php echo $reservation['number_of_guests']; ?>" required max="<?php echo $maximum_occupancy; ?>"><br><br>
<!-- Add more fields as needed -->
<input type="submit" name="update_reservation" value="Update Reservation">
</form>
<script>
document.getElementById('editForm').addEventListener('submit', function(event) {
const checkInDate = new Date(document.getElementById('check_in_date').value);
const checkOutDate = new Date(document.getElementById('check_out_date').value);
const currentDate = new Date();
if (checkInDate < currentDate) {
alert('Check-in date cannot be before the current date');
event.preventDefault(); // Prevent form submission
}
if (checkOutDate < checkInDate) {
alert('Check-out date cannot be earlier than the check-in date');
event.preventDefault(); // Prevent form submission
}
});
</script>
<?php
}
}
if (isset($_POST['update_reservation'])) {
$check_in_date = $_POST['check_in_date'];
$check_out_date = $_POST['check_out_date'];
$number_of_guests = $_POST['number_of_guests'];
$reservation_id = $_SESSION['reservation_id'];
// Perform the update query here using the collected data
$update_sql = "UPDATE Reservations
SET check_in_date = '$check_in_date', check_out_date = '$check_out_date', number_of_guests = '$number_of_guests'
WHERE id_Reservation = '$reservation_id'";
if ($conn->query($update_sql) === TRUE) {
echo "<p>Reservation updated successfully.</p>";
header("refresh:2;url=reservationdetails.php?reservation_id=$reservation_id"); // Refresh after 2 seconds and include reservation ID in the URL
// You might redirect the user or show a success message here
} else {
echo "<p>Error updating reservation: " . $conn->error . "</p>";
}
}
?>
</div>
</body>
</html>