-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbikes.php
89 lines (79 loc) · 3.1 KB
/
bikes.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
<?php
include('db_config.php');
// Check if the admin is logged in (You should have an admin authentication mechanism)
$adminLoggedIn = true; // Change this to your actual admin authentication check
if ($adminLoggedIn) {
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (isset($_POST["action"])) {
if ($_POST["action"] == "add_bike") {
// Add a new bike
$bikeName = $_POST["bike_name"];
$availabilityStatus = $_POST["availability_status"];
$sql = "INSERT INTO bikes (Bike_Name, Availability_Status) VALUES ('$bikeName', '$availabilityStatus')";
if (mysqli_query($conn, $sql)) {
echo "Bike added successfully!";
} else {
echo "Error adding bike: " . mysqli_error($conn);
}
} elseif ($_POST["action"] == "delete_bike") {
// Delete an existing bike
$bikeID = $_POST["bike_id"];
$sql = "DELETE FROM bikes WHERE Bike_ID = $bikeID";
if (mysqli_query($conn, $sql)) {
echo "Bike deleted successfully!";
} else {
echo "Error deleting bike: " . mysqli_error($conn);
}
}
}
}
// Fetch and display the list of bikes for the admin to manage
$sql = "SELECT * FROM bikes";
$result = mysqli_query($conn, $sql);
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="style.css">
<title>Admin Bike Management</title>
</head>
<body>
<div class="containerIndex">
<h1>Admin Bike Management</h1>
<h2>Add a Bike</h2>
<form action="" method="post">
<input type="hidden" name="action" value="add_bike">
<label for="bike_name">Bike Name:</label>
<input type="text" name="bike_name" required>
<label for="availability_status">Availability Status:</label>
<select name="availability_status">
<option value="Available">Available</option>
<option value="Booked">Booked</option>
</select><br><br>
<button type="submit">Add Bike</button>
</form>
</div><br>
<div class="container">
<h2>Manage Bikes</h2>
<div class="grid-container">
<?php
while ($row = mysqli_fetch_assoc($result)) {
?>
<div class="grid-item">
<p><strong>Bike ID:</strong> <?php echo $row["Bike_ID"]; ?></p>
<p><strong>Bike Name:</strong> <?php echo $row["Bike_Name"]; ?></p>
<p><strong>Availability Status:</strong> <?php echo $row["Availability_Status"]; ?></p>
<form action="" method="post">
<input type="hidden" name="action" value="delete_bike">
<input type="hidden" name="bike_id" value="<?php echo $row["Bike_ID"]; ?>">
<button type="submit">Delete</button>
</form>
</div>
<?php }} ?>
</div>
<br>
<a href="admin_bookings.php" class="admin-link">Admin Bookings</a>
</div>
</body>
</html>