Jump to content

[SOLVED] PHP delete multiple checkboxes


SocomNegotiator

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/131281-solved-php-delete-multiple-checkboxes/
Share on other sites

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.