This is a working script that lists the table entries then deletes the ones selected.
The script:
[php]
"; } ?> [/php]
The explanation . . .
First, we’ll have this:
<?php
mysql_connect("localhost", "user", "pass");
mysql_select_db("topicdb");
Simple enough, right? We’re just connecting to mysql. Next, we want to find every checkbox selected, so we’ll add to that code:
$checked = $_POST['checked'];
foreach($checked as $value) {
mysql_query("DELETE FROM `forumdb`.`topictbl` WHERE `topictbl`.`topicid` = $value") or die(mysql_error());
}
?>
$checked is all the variables we got from the form. Then it does foreach loop, which means for each checked checkbox, do this. Then it runs a simple mysql query that delets the entry by id. To write the form, then, we have this:
<form action="index.php" method="POST">
<?php
$result = mysql_query("SELECT * FROM topictbl");
while($row = mysql_fetch_array($result)) {
echo "<input type='checkbox' name='checked[]' value='" . $row['topicid'] . "' />" . $row['topicname'] . "<br />";
}
?>
<input type="submit" value="delete" />
</form>
Pretty self-explanatory; while Selecting * from topictbl, write the checkbox.