SocomNegotiator Posted November 3, 2008 Share Posted November 3, 2008 Ok this is what I have. I am not getting an error at all. What happens is that when I select an item to delete and hit the delete button the page just refreshes and that's it. The item or items that were checked do not get deleted. I am getting a value for <?=$row['id']?> so that is not the problem. Something is happening where the page is loosing the post. Because when I do echo $del_id; I get nothing. However, if I hardcore a number into the query like $del = $db->query("DELETE FROM `guide_order` WHERE id = '3'"); it works just fine. <?php while($row = $db->fetch_array()) { ?> <form id='order_form1' action='?page=guide' method='post'> <input type='hidden' name='pre_id' value='<?=$row['id']?>'/> <tr> <td align='center'><input type='text' name='amount' size='5' value='<?=$row['amount']?>' /></td> <td align='center'><?=$row['name']?></td> <td align='center'><input type='text' name='priority' size='5' value='<?=$row['priority']?>' /></td> <td align='center'><input name="checkbox[]" type="checkbox" value="<?=$row['id']?>"></td> </tr> </form> <?php } ?><br /> </table> <form id='order_form' action='?page=guide' method='post'> <input type='hidden' name='user_id' value='<?=$user_id?>'/><br /> Delivery Date: <input type="text" name="deliver" size="20" /><br /><br /> <input type='submit' name='submit' value='Submit Order'/> <input name="delete" type="submit" value="Delete"> <?php // Check if delete button active, start this $delete = $_REQUEST['delete']; if( $delete != '' ){ $checkbox = $_REQUEST['checkbox']; $count = count($_REQUEST['checkbox']); for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $del = $db->query("DELETE FROM `guide_order` WHERE id = '$del_id'"); } // if successful redirect if($del){ echo "<html><head><meta HTTP-EQUIV=\"Refresh\" CONTENT=\"1; URL=index.php?page=guide\"></html>"; } } ?> </form> Any help would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/131281-solved-php-delete-multiple-checkboxes/ Share on other sites More sharing options...
matto Posted November 4, 2008 Share Posted November 4, 2008 why are you generating a new <form> for each record in your while loop ? Quote Link to comment https://forums.phpfreaks.com/topic/131281-solved-php-delete-multiple-checkboxes/#findComment-681678 Share on other sites More sharing options...
SocomNegotiator Posted November 4, 2008 Author Share Posted November 4, 2008 why are you generating a new <form> for each record in your while loop ? Because I have an update button for each individual item. Quote Link to comment https://forums.phpfreaks.com/topic/131281-solved-php-delete-multiple-checkboxes/#findComment-681683 Share on other sites More sharing options...
SocomNegotiator Posted November 4, 2008 Author Share Posted November 4, 2008 Wow believe it or not...that was the problem. Thanks for the idea Quote Link to comment https://forums.phpfreaks.com/topic/131281-solved-php-delete-multiple-checkboxes/#findComment-681686 Share on other sites More sharing options...
matto Posted November 4, 2008 Share Posted November 4, 2008 you don't need a new <form> each time. <form methos="post" action="somepage.php"> <?php while($row = $db->fetch_array()) { //generate each checkbox and whatever else... } ?> </form> Quote Link to comment https://forums.phpfreaks.com/topic/131281-solved-php-delete-multiple-checkboxes/#findComment-681687 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.