469,271 Members | 1,370 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Deleting multiple Rows Using Checkbox

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
4 11227
code green
1,726 Expert 1GB
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
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
1,351 Expert 1GB
what errors are u getting?
Jun 11 '07 #4
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.

Similar topics

2 posts views Thread by cool_dude7244 | last post: by
4 posts views Thread by MasterChief | last post: by
11 posts views Thread by giloosh | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.