我想讓用戶檢查要刪除的項目。當用戶檢查一個或多個項目並單擊刪除按鈕時,這些數據將從數據庫中刪除。我還添加了一個搜索框來搜索DVD。搜索框起作用,但刪除沒有。這就是它在瀏覽器中的樣子。從數據庫中刪除PHP不工作
我的PHP看起來像這樣(我拿出搜索代碼):
<form action="" method="post">
<p><input type="text" name="search"> <input type="submit" value="Search"></p>
<p><input type="submit" name="deleting" value="Delete"></p>
</form>
<?php
$link = mysqli_connect($host, $user, $password, $dbname);
if (!$link) {
die('Could not connect: ' . mysqli_connect_error());
}
echo 'Connected successfully<br/>';
//searching code goes here
if (isset ($_POST['deleting']) && isset ($_POST['deleteThese']))
{
$deleteThese = implode(",", $_POST['deleteThese']);
$queryTwo = "DELETE FROM `$dbname`.`dvds` WHERE `dvds`.`DvdID` IN ($deleteThese)";
$resultTwo = mysqli_query($link, $queryTwo);
}
echo "<table border=\"1\"><tr><th>DvdTitle</th><th>RunningTime</th><th>Delete</th></tr>";
if (mysqli_num_rows($result) == 0)
echo "<tr><td colspan='2'>No records found.</td></tr>";
else {
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr><td>" . $row['DvdTitle'] . "</td>";
echo "<td>" . $row['RunningTime'] . "</td>";
echo "<td>" . "<form>" . "<input type='checkbox' name='deleteThese[]' value='" . $row['DvdID'] . "' >" . "</form>" . "</td></tr>\n";
}
}
echo "</table>";
mysqli_free_result($result);
mysqli_close($link);
?>
每個DvdTitle有一個獨特的DVD ID,每行的,因此值是DVD的ID $row['DvdID']
。
你沒有錯誤('error_reporting(E_ALL);')? – 2013-03-24 23:28:03
nope,沒有錯誤 – 2013-03-24 23:30:24
print_r($ queryTwo); die(); //複製粘貼並在phpMyAdmin中手動運行或其他:) – FeRtoll 2013-03-24 23:32:59