predator Posted July 14, 2006 Share Posted July 14, 2006 hey i got this for each loop if($_POST['remove']){ foreach($_POST['remove'] as $k=>$v){ mysql_query("DELETE FROM sections WHERE id='$v' LIMIT 1"); } }and i am getting the error ofWarning: Invalid argument supplied for foreach()the $_POST['remove'] is an array i get from an html page and it has a products id assigned to it but i just cant work out why this is giving me an error.any help greatly apprechiated RegardsMark Quote Link to comment https://forums.phpfreaks.com/topic/14588-why-am-i-getting-problems-with-this-foreach-loop/ Share on other sites More sharing options...
wildteen88 Posted July 14, 2006 Share Posted July 14, 2006 If you are getitng that error then $_POST['remove'] is not an array. Try this code:[code=php:0]echo '<pre>' . print_r($_POST['remove'], true) . '</pre>';[/code]What does that return?Also if you have input fields that have the same name as remove make sure you have add the square brackets after the name, eg: remove[] Quote Link to comment https://forums.phpfreaks.com/topic/14588-why-am-i-getting-problems-with-this-foreach-loop/#findComment-57943 Share on other sites More sharing options...
effigy Posted July 14, 2006 Share Posted July 14, 2006 Are you sure it is an array? Make sure it has [] after the name in HTML, and use is_array in PHP to double check. Quote Link to comment https://forums.phpfreaks.com/topic/14588-why-am-i-getting-problems-with-this-foreach-loop/#findComment-57944 Share on other sites More sharing options...
predator Posted July 14, 2006 Author Share Posted July 14, 2006 yes it is an array the name of each check box is remove[{$content[i].id}]where $content is obviously the id that will be passed into each remove element.personally i dont like this way of coding however i have taken this project over at work and cant totally re write the code as the customer needs it done obviously sooner than laterregardsMark Quote Link to comment https://forums.phpfreaks.com/topic/14588-why-am-i-getting-problems-with-this-foreach-loop/#findComment-57955 Share on other sites More sharing options...
akitchin Posted July 14, 2006 Share Posted July 14, 2006 it would still be nice to see the input's HTML to verify that it isn't a spelling or notation error. Quote Link to comment https://forums.phpfreaks.com/topic/14588-why-am-i-getting-problems-with-this-foreach-loop/#findComment-58035 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.