Jump to content

Selecting Checkbox And Deleting Mysql Table Rows


sridaran

Recommended Posts

Hi I have database table with checkbox for each row on my webpage. If I check the boxes and click delete, those rows should be deleted on database. Here is my php code. Can anyone tell me how to proceed further?<form name="form1" method="post"><table width="70%" border="1"><?php require("database.php"); $srno=0; $query = "select * from groups"; $q1 = mysql_query($query) or die(mysql_error()); while($row=mysql_fetch_assoc($q1)){ $srno++; @extract($row); ?> <tr> <td><input name="chkbox<?=$srno?>" type="checkbox" value="<?=$group_id?>"></td> <td><?=$group_name?></td> <td><?=$group_desc?></td> </tr> <?php } ?></table><a href="">Check All</a><a href="">Clear All</a><a href="">Delete Checked</a></form>

Link to comment
Share on other sites

Give all of your checkboxes the same name so that they end up in an array in PHP. Since you're giving each checkbox the value you want to delete, the array will be the IDs to delete. You end the name with square brackets to make it an array in PHP:<input name="delete_ids[]" type="checkbox" value="<?=$group_id?>">In the processing script, you get $_POST['delete_ids'] and it will be your array of IDs. It's probably best to loop through it and delete each record, or you can join the IDs with commas and put the entire list in one delete query.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...