I'm new to php and currently I'm preparing a small crud project. I have a html homepage, add_reservation.php which is working, show_bookings.php and delete_booking.php.
I can not delete a booking.
Here is my show_bookings.php code:
<?php
include 'db_connection.php';
$sqlQuery = 'SELECT * FROM room_reservation';
$result = mysqli_query($link, $sqlQuery) or die(mysqli_error($link));
if ($result) {
$tableStyle = "style='border:1px solid white; border-collapse:collapse; text-align:center; background-color:#8f50fb'";
$buttonStyle = "style='background-color: #8f50fb; color=white; padding: 14px 25px; text-align:center; border-radius:10px'";
echo "<table class='table table-striped table-borderrer'><tr><th>Name</th><th>Room</th><th>CheckIn</th><th>CheckOut</th><th>Actions</th></tr>";
while ($row = mysqli_fetch_array($result)) { //to loop through the result row by row
echo "<tr>";
echo "<td>".$row['Name']."</td>";
echo "<td>".$row['Room']."</td>";
echo "<td>".$row['CheckIn']."</td>";
echo "<td>".$row['CheckOut']."</td>";
echo "<td><div class='btn-group'>";
echo "<a class='btn btn-danger' href='./delete_booking.php?Name=" .$row['Name'] ."'>Delete</a>";
echo"</div></td>";
echo "</tr>";
}
echo "</table>";
}
echo '<p><a href="add_reservation.php">Add a new student</a></p>';
echo "<a href='homepage.html' $buttonStyle>Go back to homepage</a>"
?>
And here is my delete_booking.php code:
<?php
// Connect to the database
include 'db_connection.php';
// Check if the form has been submitted
if (isset($_GET['Name'])) {
// Get the ID of the record to be deleted
$name = $_GET['Name'];
// Delete the record from the database
$query = "DELETE FROM table WHERE Name = $name";
// mysqli_query($db, $query);
// Redirect to the home page
// header("Location: show_bookings.php");
// exit;
}
?>
I hope that someone could tell me where I'm wrong.