進入的形象在這裏描述PHP刪除按鈕總是開始刪除最後一行
好了,所以這可能只是簡單的爲你們既然你有經驗,但我可以」我不知道爲什麼每次我在我的表的第一行點擊「刪除」按鈕時,它會刪除最後一行,而不是我點擊「刪除」的行。只發生在第一行。第二行會在數據庫上完美刪除。
我的代碼有什麼問題,或者我的表結構有問題嗎?我已經提供了兩個單獨的php文件的代碼,即booklist.php和edit.php,我將非常感謝您的幫助,因爲我對PHP非常感興趣。還不熟悉所有的規則,什麼不是。謝謝。
//booklist.php below
echo "<form method='POST' action='edit.php'>";
while($row = mysql_fetch_array($result))
{
$bookID_Var = $row['No'];
$titleVar = $row['Title'];
$authorVar = $row['Author']; //authorVar is a variable container for the value of Author row in librarydatabase
$ISBN = $row['ISBN'];
echo "<tr>";
echo "<td>" .$bookID_Var. "</td>";
echo "<td>" . $titleVar. "</td>"; // there's no need to quote variables. In this line, we used variables $authorVar and $titleVar
echo "<td>" . $authorVar. "</td>";
echo "<td>" . $ISBN . "</td>";
echo "<td> <input type='submit' value='Edit'> </td>"; // Edit button
echo "<td> <input type='submit' name='delete' value='Delete'> </td>"; // Delete button
echo "</tr>";
echo "<input type='hidden' name='bookID' value=' " .$bookID_Var. " '>";
} // end of while loop
echo "</form>";
//edit.php below
<?php
if (isset($_POST['delete'])) {
echo "entered delete if block <br />";
echo "Value: " . $_REQUEST['bookID'];
$bookID = $_REQUEST['bookID'];
$sql = " DELETE FROM booklist WHERE No='$bookID' ";
$result = mysql_query($sql);
if ($result) {
echo "Successfully deleted" . "Book ID: " . $bookID;
}
} // end of main if
?>
它涉及到phpmyadmin的工具而不是PHP語言 –