I wrote the code in PHP like this and I need to delete the rows from the database which "delete checkbox" in its delete column checked. And I want to send "verify" value (1 or 0) to the database. But I don't know SQL command to delete checked rows and I don't know how to get value of "verify" column (because it isn't possible to get the value using $_POST[$id])
.
<?php
echo "<form action=\"index.php?go=save\" method=\"POST\">
<table width=\"335\" border=\"1\">
<tr>
<th width=\"19\" scope=\"col\">ID</th>
<th width=\"31\" scope=\"col\">Title</th>
<th width=\"33\" scope=\"col\">URL</th>
<th width=\"52\" scope=\"col\">Visitors</th>
<th width=\"28\" scope=\"col\">Hits</th>
<th width=\"52\" scope=\"col\">Verify</th>
<th width=\"27\" scope=\"col\">Edit</th>
<th width=\"41\" scope=\"col\">Delete</th>
</tr>";
$query = mysql_query("SELECT * FROM posts ORDER BY visitors DESC");
while($write = mysql_fetch_array($query)) {
$id = $write['id'];
$title = $write['title'];
$url = $write['url'];
$visitors = $write['visitors'];
$hits = $write['hits'];
echo"
<tr>
<td>$id</td>
<td>$title</td>
<td>$url</td>
<td>$visitors</td>
<td>$hits</td>
<td>
<input type=\"radio\" name=\"$id\" value=\"1\" />Yes
<input type=\"radio\" name=\"$id\" value=\"0\" />No
</td>
<td><a href=\"index.php?go=edit\">Edit</a></td>
<td>
<input type=\"checkbox\" name=\"$id\" />
</td>
</tr>";
}
echo "</table>
<input type=\"submit\" value=\"Save\" />
</form> ";
?>
Please, help me to solve this problem. If you know alternative variants, please write it.
Delete column:
<input type=\"checkbox\" name=\"delete[]\" value=\"$id\" />
Checking and deleting:
foreach($_POST['delete'] as $id_to_delete) {
mysql_query("DELETE FROM posts WHERE ID=".$id_to_delete)
}