By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 881 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

Deleting multiple Rows Using Checkbox

P: 25
Hi ,
I am trying to figure out why my PHP code to delete multiple value by selecting the checkbox is not working. My php code is listed as below

[PHP]
<?php
$sql = "Select * from list;";
$result=mysql_query($sql) or die ("<br> Could not Retrieve Data <br>");
$num_rows=mysql_num_rows($result);

While ($row =mysql_fetch_array($rs))
{
$currentCom_id = $row["com_id"];
?>

<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['com_id']; ?>">
.....
.....
<?php

}
?>

<input name="delete" type="submit" id="delete" value="Delete">
[/PHP]

Now for deleting the selected checkbox i have used following SQL queries.

[PHP]

if($_POST['delete'] == "Delete"){
for($j=0;$j<$num_rows;$j++){
$del_id = $checkbox[$j];
$sql = "DELETE FROM committee WHERE com_id='$del_id'";
$result = mysql_query($sql);
echo $result;
}
}
mysql_close();
?>

[/PHP]

The problem is when i press delete it does not deletes the rows selected, else it just reloads the page. I dont know where i am wrong.

can u guyz please help me on this ...
THanks
Apr 8 '07 #1
Share this Question
Share on Google+
4 Replies


code green
Expert 100+
P: 1,726
Looks like you are expecting the GLOBAL post vars to be switched on. It is switched off by default in later versions of php. You should not use this anyway. You need to read the checkbox values through the $_POST array
Apr 10 '07 #2

P: 1
Hi,

i'm gaing the same problem... I change my code to that:

<?
// Check if delete button active, start this
if($_POST['delete'] == 'Delete'){
for($i=0;$i<$count;$i++){
$del_id = $_POST['checkbox'][$i];
$sql = "DELETE FROM $tbl_name WHERE userid='$del_id'";
$result = mysql_query($sql);
}


// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">";
}
}
mysql_close();
?>


But it still doesn't work...

Please help.
thx.
Jun 11 '07 #3

epots9
Expert 100+
P: 1,351
what errors are u getting?
Jun 11 '07 #4

P: 1
Hi, If any one didn't got the solution yet of this problem and still seeking! Please mail me on DELETED
Feb 13 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.