[英]php deleting a table row
我正在為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>';
}
?>
這是刪除行的代碼
關於行出錯的任何建議都不會刪除
似乎您正在將tid作為GET變量傳遞到查詢字符串中,但是表單的方法是POST。 請注意,confirmBooking和denyBooking表單都存在相同的問題
<form action="denyBooking.php?tid=' . $row['id'] . '" method="post">
應該
<form action="denyBooking.php?tid=' . $row['id'] . '" method="get">
您遇到了多種問題,這些問題將導致您的記錄無法在數據庫中刪除:
解:
創建一個隱藏字段並使用$ row ['id']為其賦值
<input type="hidden" name="rowId" value="' . $row['id'] . '">
該ID將在$_POST['rowId']
其他說明:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.