I am writing a booking system for uni and have encountered an issue i need help with.
<?php
$title = 'Room Booking';
require_once 'header.php';
?>
<ul>
<?php
$query = "SELECT * FROM `room1booking` ORDER BY date, start, id";
if ($result = mysqli_query($db_server, $query)) {
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
echo '<li>
' . $row['name'] . '
' . $row['date'] . '
' . $row['start'] . '
<form action="confirmBooking.php?tid=' . $row['id'] . '" method="post">
<button type="submit" name="submit"><a href="confirmBooking.php?tid=' . $row['id'] . '">Confirm</a></button>
</form>
<form action="denyBooking.php?tid=' . $row['id'] . '" method="post">
<button type="submit" name="submit"><a href="denyBooking.php?tid=' . $row['id'] . '">Deny</a></button>
</form>
</li>
';
}
} else {
echo '<li>There are no results</li>';
}
mysqli_free_result($result);
}
mysqli_close($db_server);
?>
</ul>
</form>
This code is for the selecting of which row in the table that you want to delete
<?php
$title = 'Delete The Booking';
require_once 'header.php';
if(isset($_GET['submit'])){
$tid = mysqli_real_escape_string($db_server, trim($_GET['tid']));
if(!empty($tid)){
$query = "DELETE FROM room1booking WHERE id = '$tid'";
mysqli_query($db_server, $query);
echo '<p>You have successfully deleted the booking.</p>';
}
} else {
echo '<p>There is a problem with the system.</p>';
}
?>
And this is the code to delete the row
Any suggestions on where i am going wrong as the row won't delete
it seems like you are passing the tid as a GET variable in the query string but the method of the form is POST. Note that both the confirmBooking and denyBooking forms have the same problem
<form action="denyBooking.php?tid=' . $row['id'] . '" method="post">
should be
<form action="denyBooking.php?tid=' . $row['id'] . '" method="get">
You have a combination of problems that would cause your record to not delete in the database:
Solution:
Create a hidden field and assign it's value using $row['id']
<input type="hidden" name="rowId" value="' . $row['id'] . '">
And the id will be in $_POST['rowId']
Other notes:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.