Okay, so this may be just simple for you guys since you have experience but I can't get to figure out why is it that everytime I hit "Delete" button on the first row of my table, it deletes the last row instead of the row on which I hit "Delete." Only happens on the first row. Second row would delete just perfectly on the database.
Is there anything wrong with my code or is there a problem with my table structure? I've provided my code for two separate php files namely booklist.php and edit.php I would appreciate your help as I am really new with PHP. Not yet familiar with all the rules and what not. Thanks.
//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
?>


