I have been trying to delete certain rows from the database using a few checkboxes. So far I've managed to echo out the content of the MySQL table but deleting rows through the checkboxes doesn't seem to work.
<table class="ts">
<tr>
<th class="tg-031e" style='width:1px'>ID</th>
<th class="tg-031e">IP address</th>
<th class="tg-031e">Date added</th>
<th class="tg-031e">Reason</th>
</tr>
<?php include 'connect.php';
$SQL = "SELECT `ID`, `IPaddress`, `DateAdded`, `Reason` FROM `banned`";
$exec = mysql_query($SQL, $connection);
while ($row = mysql_fetch_array($exec)){
echo "<tr class='tg-031h'>";
echo "<td class='tg-031e'><form method='post'><input type='checkbox' name='checkbox' value=" . $row['ID'] . "></form></td>";
echo "<td class='tg-031e'>" . $row['IPaddress'] . "</td>";
echo "<td class='tg-031e'>" . $row['DateAdded'] . "</td>";
echo "<td class='tg-031e'>" . $row['Reason'] . "</td>";
echo "</tr>";
}
echo "</table><form method='post'><input name='delete' type='submit' value='Delete'></form>";
if (isset($_POST['delete']) && isset($_POST['checkbox'])) {
foreach($_POST['checkbox'] as $id){
$id = (int)$id;
$delete = "DELETE FROM banned WHERE ID = $id";
mysql_query($delete);
}
}
?>
I don't get any result as the check does not pass but I don't know what's wrong with it. The query is correct though, so the issue must be with selecting the checkboxes and getting their ID.