Xtremer360 Posted May 29, 2011 Share Posted May 29, 2011 For some reason I'm getting an invalid argument supplied for foreach error and I'm not sure why. <?php // Include the database page require ('../inc/dbconfig.php'); if (isset($_POST['edit_event_lineup'])) { $event_items = $_POST['event_items']; $event_id = (int)$_POST['event_id']; foreach ($event_items as $items) { print_r($items); $segment_writer_id = (int)$_POST['segment_writer_id']; $introduction = mysqli_real_escape_string($dbc, $_POST['introduction']); $conclusion = mysqli_real_escape_string($dbc, $_POST['conclusion']); $segment_type = mysqli_real_escape_string($dbc, $_POST['segment_type']); $match_number = (int)$_POST['match_number']; $segment_number = (int)$_POST['segment_number']; $match_type_id = (int)$_POST['match_type_id']; $segment_title = mysqli_real_escape_string($dbc, $_POST['segment_title']); $match_type_id = mysqli_real_escape_string($dbc, $_POST['match_type_id']); $titles_id_list = mysqli_real_escape_string($dbc, $_POST['titles_id_list']); $stipulations_id_list = mysqli_real_escape_string($dbc, $_POST['stipulations_id_list']); $characters_id_list = mysqli_real_escape_string($dbc, $_POST['character_id_list']); $preview = mysqli_real_escape_string($dbc, $_POST['preview']); } $query = "INSERT INTO `event_segments` (event_id, segment_writer_id, segment_type, sort_order_preview, segment_title, preview, is_submitted_yes_or_no_id) VALUES ('".$event_id."', '".$match_writer_id."', '".$segment_type."' ,'".$sort_order_preview."','".$segment_title."','".$preview."',2)"; mysqli_query($dbc, $query); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/ Share on other sites More sharing options...
mikesta707 Posted May 29, 2011 Share Posted May 29, 2011 $event_items is a single value, and foreach expects an array. Do you expect $_POST['event_items'] to be an array? If so why do you expect this? Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/#findComment-1221925 Share on other sites More sharing options...
Xtremer360 Posted May 29, 2011 Author Share Posted May 29, 2011 The odd thing is inside of my post parameters for FB I have this for event_items: event_items [object Object],[object Object],[object Object],[object Object],[object Object],[object Object] Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/#findComment-1221926 Share on other sites More sharing options...
mikesta707 Posted May 29, 2011 Share Posted May 29, 2011 Hmm interesting, so it is an array? If you do a print_r on $event_items what do you get? Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/#findComment-1221929 Share on other sites More sharing options...
Xtremer360 Posted May 29, 2011 Author Share Posted May 29, 2011 Same thing. Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/#findComment-1221931 Share on other sites More sharing options...
mikesta707 Posted May 29, 2011 Share Posted May 29, 2011 What exactly does it say. Can you copy paste it... Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/#findComment-1221934 Share on other sites More sharing options...
Xtremer360 Posted May 29, 2011 Author Share Posted May 29, 2011 [object Object],[object Object],[object Object],[object Object],[object Object],[object Object]<br /> <b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/xtremer/public_html/efedmanager/processes/bookings.php</b> on line <b>10</b><br /> Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/#findComment-1221936 Share on other sites More sharing options...
mikesta707 Posted May 29, 2011 Share Posted May 29, 2011 Hmm, well can you post the page that is posting the information to the code you posted in your OP Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/#findComment-1221938 Share on other sites More sharing options...
Xtremer360 Posted May 29, 2011 Author Share Posted May 29, 2011 I'll send you a PM. Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/#findComment-1221939 Share on other sites More sharing options...
xyph Posted May 29, 2011 Share Posted May 29, 2011 $_POST should never be populated with an object. The only way it will be populated with an array is if you've named your files with a [] at the end, ie <select name="some_name[]" multiple="multiple" size="3"> Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/#findComment-1221999 Share on other sites More sharing options...
mikesta707 Posted May 30, 2011 Share Posted May 30, 2011 $_POST should never be populated with an object. The only way it will be populated with an array is if you've named your files with a [] at the end, ie <select name="some_name[]" multiple="multiple" size="3"> yeah this is what confused me. I was hoping he would post the code that actually sends the post data, but instead he decided to PM the link to the page.. which didn't help at all Quote Link to comment https://forums.phpfreaks.com/topic/237788-foreach-loop/#findComment-1222062 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.