...

View Full Version : Deleting Multiple Rows using Checkboxes



gismo
04-26-2004, 03:41 PM
Hi all,

I am having a lot of problems getting this working. The follwoing is the code that i am using:

printf("<tr><td><input type = checkbox name = \"delete[]\" value = \"<?=$myarray[$id]?>\"> </td></tr>, $myrow['name']);

<form method = "post" action="delete.php">
<input type="submit" name="delete" value = "delete">

Delete.php:

if(!$id]){
echo "<b>Please make your selection.</b>";
}//end if
else {
$sql = "DELETE FROM register WHERE id = '$myarray[$id]'";
$result = mysql_query($sql);
echo "<b>Information deleted.";
}//end else

Any help would greatly appreciated

Thank You
Gismo

raf
04-26-2004, 06:13 PM
try changing
$sql = "DELETE FROM register WHERE id = '$myarray[$id]'";
to
$sql = "DELETE FROM register WHERE id = '$_POST['myarray']";

gismo
04-26-2004, 06:53 PM
Hi,

Thanks for your reply but it doesnt seem to work, its bringing up the following error:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'

Any suggestions?
Thank you
Gismo

raf
04-26-2004, 07:03 PM
Missed a quote. Try

$sql = "DELETE FROM register WHERE id = '$_POST['delete']'";

gismo
04-27-2004, 03:10 PM
Thanks again, but it is bringing up the same error:

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'

Your help is very appreciated

Thanks
Gismo

raf
04-27-2004, 03:34 PM
Hmm. The query isn't correct anyway since you'll have a commadelimited list in $_POST['delete'] and i missed the '."' behind the postvariable.
Normally, the id will have a numerical column-type, so no quotes are needed. Your query is then


$sql = "DELETE FROM register WHERE id In (" .$_POST['delete'] .")";

If id is not a numerical column, then you either need to change the columntype in your db or set up some extra formprocessing where you loop through the array to buils a variable with the elements in, so that theu are enclosed in quotes.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum