-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_bookings.php
79 lines (70 loc) · 3.16 KB
/
admin_bookings.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
<?php
include('db_config.php');
// Check if the "Delete" button is clicked
if (isset($_POST['action']) && $_POST['action'] === 'delete_booking') {
$bookingID = $_POST['booking_id'];
// Get the associated bike ID
$bikeIDQuery = "SELECT Bike_ID FROM manage WHERE Booking_ID = $bookingID";
$bikeIDResult = mysqli_query($conn, $bikeIDQuery);
if ($bikeIDResult && mysqli_num_rows($bikeIDResult) > 0) {
$row = mysqli_fetch_assoc($bikeIDResult);
$bikeID = $row['Bike_ID'];
// Update the bike availability status to 'Available'
$updateBikeStatusQuery = "UPDATE bikes SET Availability_Status = 'Available' WHERE Bike_ID = $bikeID";
mysqli_query($conn, $updateBikeStatusQuery);
// Delete the booking from the "manage" table
$deleteQuery = "DELETE FROM manage WHERE Booking_ID = $bookingID";
if (mysqli_query($conn, $deleteQuery)) {
// Successful deletion
header("Location: admin_bookings.php");
exit;
}
}
}
// Query to retrieve data from the "manage" table
$sql = "SELECT m.Booking_ID, m.User_ID, m.Bike_ID, m.Booking_Date, m.Return_Date, u.first_name, u.last_name, u.email, u.telephone, b.Bike_Name
FROM manage m
INNER JOIN users u ON m.User_ID = u.User_ID
INNER JOIN bikes b ON m.Bike_ID = b.Bike_ID";
// Execute the query
$result = mysqli_query($conn, $sql);
?>
<!DOCTYPE html>
<html>
<head>
<title>View Manage Table</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
<h1>View Manage Table</h1>
<div class="grid-container"> <!-- Add the grid container -->
<?php
while ($row = mysqli_fetch_assoc($result)) {
echo '<div class="grid-item">'; // Use grid items for each table row
echo '<p><strong>Booking ID:</strong> ' . $row['Booking_ID'] . '</p>';
echo '<p><strong>User ID:</strong> ' . $row['User_ID'] . '</p>';
echo '<p><strong>Bike ID:</strong> ' . $row['Bike_ID'] . '</p>';
echo '<p><strong>Bike Name:</strong> ' . $row['Bike_Name'] . '</p>';
echo '<p><strong>Booking Date/Time:</strong> ' . $row['Booking_Date'] . '</p>';
echo '<p><strong>Return Date/Time:</strong> ' . $row['Return_Date'] . '</p>';
echo '<p><strong>First Name:</strong> ' . $row['first_name'] . '</p>';
echo '<p><strong>Last Name:</strong> ' . $row['last_name'] . '</p>';
echo '<p><strong>Email:</strong> ' . $row['email'] . '</p>';
echo '<p><strong>Telephone:</strong> ' . $row['telephone'] . '</p>';
// Add a form to delete the booking
echo '<form action="" method="post">';
echo '<input type="hidden" name="action" value="delete_booking">';
echo '<input type="hidden" name="booking_id" value="' . $row['Booking_ID'] . '">';
echo '<button type="submit">Delete</button>';
echo '</form>';
echo '</div>';
}
?>
</div>
<br>
<a href="bikes.php" class="admin-link">Bikes Page</a>
</div>
</body>
</html>