Delete using check box
Posted: Fri Jul 04, 2003 8:22 pm
Hey , I am trying to delete information from mysql table using check boxs. If i tick the first record and next and next etc it deletes them, but if i dont tick the first record and do e.g the 3rd record, it does not delete it.
Here is the code for listing the records with check boxs
I have missed out database connection and some echo
Here is the code for deleteing the information from database
Can anyone help
Many thanks
Here is the code for listing the records with check boxs
Code: Select all
<?php
<form name="delete" method="post" action="delmsg.php">
<input type="Submit" name="submit" value="Delete">
<?php $sql = "SELECT * FROM contact where type = 'msg'" ;
$rs=mysql_query($sql,$db);
while ($r = mysql_fetch_array($rs))
{
$msg=$r["msg"];
$name=$r["name"];
$email=$r["email"];
$comments=$r["comments"];
$date = strtotime($r["date"]);
$date = date("F jS y", $date); ?>
<?php echo $name ?>
<input type="Checkbox" name="msg[]" value="<? echo $msg; ?>">
</form>
<?php
}
?>Here is the code for deleteing the information from database
Code: Select all
<?php
for ($x=0; $x<sizeof($msg); $x++)
{
$db =mysql_connect("l","j", "");
mysql_select_db("",$db) or die ("cannot connect to database");
$query = "delete from contact where msg = '$msg[$x]'";
mysql_query($query);
}
header("Location:msg.php");
?>Many thanks