I’m currently facing a strange issue whereby I did not get any errors from my debugging page. My table consists of several rows and only the first row of the table can’t be deleted.
Sample form:
$DB = new PDO('sqlite:database/Sample.db');
$result = $DB->query("select * from staff");
foreach ($result as $row)
{
$StaffNo= $row['StaffNo'];
$Name= $row['Name'];
$TelNo= $row ['TelNo'];
echo "<tr>";
//Go to remove.php to remove
echo "<form action=\"Remove.php\" method=\"post\">";
echo "<input type=\"hidden\" name=\"StaffNo\" value=\"$StaffNo\">";
echo "<input type=\"submit\" onclick=\"return confirm('Yes/No')\"/>";
echo "</form>";
echo "</td>";
echo '<td data-column-name="Name" char="data">'.$Name.'</td>';
echo '<td data-column-name="TelNo" char="data">'.$TelNo.'</td>';
</tr>
}
Remove.php:
$StaffNo= $_POST["StaffNo"];
$DB = new PDO('sqlite:database/Sample.db');
$DB->query("DELETE FROM Staff WHERE StaffNo=".$StaffNo);
@header("location:view.php");
From my code above, I can delete all my sample records except for the first row. It doesn’t get deleted… Kindly advise if i did wrong somewhere….
I’ve tried your code and apart from the broken table code, everything seems fine. Make sure your table is correct (
<table><tr><td>Content</td></tr></table>). In your question, you’re missing an opening<td>on line 9 of the first file, as well as missing<table>tags. Some browsers don’t handle broken tables very well and that might mess up your form.Your query will also break if
$StaffNois an empty string, so double check that.You can also try removing the
header()call and print out errors using$DB->errorInfo().