我正在为uni写一个预订系统,遇到了一个我需要帮助的问题。
<?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>
此代码用于选择表中要删除的行
<?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>';
}
?>
这是删除行的代码
关于我哪里出错的任何建议,因为该行不会删除
答案 0 :(得分:0)
您似乎将tid作为查询字符串中的GET变量传递,但表单的方法是POST。请注意,confirmBooking和denyBooking表单都有相同的问题
<form action="denyBooking.php?tid=' . $row['id'] . '" method="post">
应该是
<form action="denyBooking.php?tid=' . $row['id'] . '" method="get">
答案 1 :(得分:0)
您有一系列问题会导致您的记录无法在数据库中删除:
<强>解决方案:强>
创建隐藏字段并使用$ row ['id']
指定其值<input type="hidden" name="rowId" value="' . $row['id'] . '">
并且ID将在$_POST['rowId']
其他说明: