Xtremer360 Posted July 21, 2011 Share Posted July 21, 2011 I'm not sure why but I'm getting a <b>Warning</b>: Invalid argument supplied for foreach(). if (isset($_POST['deleteContentPagesArray'])){ $contentPageIDs = $_POST['contentPageArray']; foreach ($contentPageIDs as $contentPageID) { $deleteQuery = "UPDATE `manager_site_contentPages` SET `status` = 'Deleted' WHERE `id` = '".$contentPageID."' LIMIT 1"; mysqli_query($dbc,$deleteQuery); // Delete was sucessful $errors = false; $output = array('errorsExist' => $errors); } } Quote Link to comment https://forums.phpfreaks.com/topic/242555-invalid-argument-supplied-for-foreach/ Share on other sites More sharing options...
premiso Posted July 21, 2011 Share Posted July 21, 2011 $contentPageIDs = !empty($_POST['contentPageArray'])?$_POST['contentPageArray']:array(); Should fix your issue. Since POST data is unreliable, it is better to check that you have content you are expecting. If not default it or throw an error to handle it properly. Quote Link to comment https://forums.phpfreaks.com/topic/242555-invalid-argument-supplied-for-foreach/#findComment-1245689 Share on other sites More sharing options...
Xtremer360 Posted July 21, 2011 Author Share Posted July 21, 2011 I'm still getting the same thing. Quote Link to comment https://forums.phpfreaks.com/topic/242555-invalid-argument-supplied-for-foreach/#findComment-1245690 Share on other sites More sharing options...
premiso Posted July 21, 2011 Share Posted July 21, 2011 Then your post variable coming in is not an array. Do a var_dump($_POST['contentPageArray']); and see what is happening. Quote Link to comment https://forums.phpfreaks.com/topic/242555-invalid-argument-supplied-for-foreach/#findComment-1245692 Share on other sites More sharing options...
Xtremer360 Posted July 21, 2011 Author Share Posted July 21, 2011 string(3) "2,3" Quote Link to comment https://forums.phpfreaks.com/topic/242555-invalid-argument-supplied-for-foreach/#findComment-1245697 Share on other sites More sharing options...
premiso Posted July 21, 2011 Share Posted July 21, 2011 Ok, so the obvious problem is that you do not have an array. $contentPageIDs = !empty($_POST['contentPageArray']) ? explode(',', $_POST['contentPageArray']) : array(); Should fix your troubles. Quote Link to comment https://forums.phpfreaks.com/topic/242555-invalid-argument-supplied-for-foreach/#findComment-1245702 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.