472,146 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,146 software developers and data experts.

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 11365
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
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.