Lamez Posted May 14, 2010 Share Posted May 14, 2010 I have a multiple checkbox page. I have handled these before, well. However, this time I am getting a strange error. Here it is: Warning: Invalid argument supplied for foreach() in C:\wamp\www\TheSportZone Store\admin\manageAdmin.php on line 10 Here is Line 10: foreach($_POST['del'] as $id){ Entire foreach body: foreach($_POST['del'] as $id){ mysql_query("DELETE FROM ".TBL_ADMINS." WHERE id = '$id'"); } Any ideas? I have done this before, as such, and it worked well. Link to comment https://forums.phpfreaks.com/topic/201789-foreach-question/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 14, 2010 Share Posted May 14, 2010 http://us3.php.net/is_array Link to comment https://forums.phpfreaks.com/topic/201789-foreach-question/#findComment-1058468 Share on other sites More sharing options...
kenrbnsn Posted May 14, 2010 Share Posted May 14, 2010 What does the form look like that $_POST['del'] is being generated from? Ken Link to comment https://forums.phpfreaks.com/topic/201789-foreach-question/#findComment-1058469 Share on other sites More sharing options...
Lamez Posted May 14, 2010 Author Share Posted May 14, 2010 Hmm, something like this? if(is_array($_POST['del'])){ foreach($_POST['del'] as $id){ mysql_query("DELETE FROM ".TBL_ADMINS." WHERE id = '$id'"); } }else mysql_query("DELETE FROM ".TBL_ADMINS." WHERE id = '$id'"); Link to comment https://forums.phpfreaks.com/topic/201789-foreach-question/#findComment-1058471 Share on other sites More sharing options...
Lamez Posted May 14, 2010 Author Share Posted May 14, 2010 I could post the entire form, lol - not, but I will post this: <?php $id = $f['id']; ?> <input type="checkbox" name="del" id="del" value="<?php echo $id; ?>"> Link to comment https://forums.phpfreaks.com/topic/201789-foreach-question/#findComment-1058472 Share on other sites More sharing options...
kenrbnsn Posted May 14, 2010 Share Posted May 14, 2010 This <input type="checkbox" name="del" id="del" value="<?php echo $id; ?>"> will not create an array in the processing script. This <input type="checkbox" name="del[]" id="del_<?php echo $id ?>" value="<?php echo $id; ?>"> will Ken Link to comment https://forums.phpfreaks.com/topic/201789-foreach-question/#findComment-1058485 Share on other sites More sharing options...
Lamez Posted May 14, 2010 Author Share Posted May 14, 2010 Gosh, how could I miss that. Thanks. I feel so dumb after you guys fix my mistakes. Link to comment https://forums.phpfreaks.com/topic/201789-foreach-question/#findComment-1058489 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.