I need help on how to delete multiple messages from a database.
$query = "select * from db ";
$result = mysql_db_query($db,$query ,$connection);
while($rows=mysql_fetch_array($result)
{
$msgid = $myrows["msgid"];
$title = $title["title"];
echo "<input type=checkbox name=\"delid[]\" value=$msgid>$title <p>";
echo "<input type=submit>";
}
The above will retrieve info from the database, and display each record, line by line.
Each record will have a checkbox next to it.
What I want to do is let the user check all the messages he wants to delete.
Then I need to collect all the checked messages, and form a query that will delete them from the database. I thought using delid[] will put all the messages in an array.
Below is my attemp:
for($i=0; $i<sizeof($delid); $i++)
{
$query = "delete from db where msgid='$delid[$i]' ";
$result = mysql_db_query($db,$query ,$connection);
}
The above deletes all messages, regardless of how many messages the user checked. In other words, even if user checks one messages, all messages in the db are deleted.
Kindly take a look at this and see where I've made a mistake.
Thanks.
Richie.