msaz87 Posted January 1, 2010 Share Posted January 1, 2010 Hey all, I'm getting the following error and am not sure why: Warning: Invalid argument supplied for foreach() in /[PATH TO]/[FILE].php on line 97 I'm using about five or six foreach's and this is the only one failing... foreach($_POST['manager'] as $key => $value){ list($payment_id,$d) = explode('|',$key); mysql_query(" UPDATE [DB].other_payments SET manager_id = '$value' WHERE other_payment_id = '$payment_id'") or die(mysql_error()); } The code for the form is: <select name="manager[<?php echo $payment_id; ?>|i]"> <?php $managers_list_query = " SELECT * FROM [DB].user ORDER BY user_name"; $managers_list_results = mysql_query($managers_list_query) or die(mysql_error()); while($row = mysql_fetch_array($managers_list_results)){ ?> <option <?php if($manager == $row['user_id']) echo "selected" ?> value="<?php echo $row['user_id']; ?>"><?php get_manager_name_from_id($row['user_id']) ?></option> <?php } ?> </select> ... and a look at how the above code outputs onto the page: <select name="manager[2|i]"> <option value="1">User 1</option> <option value="6">Darren</option> <option value="13">Elliot</option> <option value="5">Eric</option> <option value="9">Julia</option> <option value="11">Lee</option> <option selected value="4">Matt</option> <option value="7">Richard</option> <option value="3">Ryan</option> </select> And before you ask, the $d variable isn't used for anything... it's just sort of the result of me copying and pasting this same foreach over and over and just never taking it out... Any help is greatly appreciated -- thanks! Quote Link to comment https://forums.phpfreaks.com/topic/186883-help-with-invalid-argument-with-foreach/ Share on other sites More sharing options...
teamatomic Posted January 2, 2010 Share Posted January 2, 2010 $_POST['manager'] is not an array? HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/186883-help-with-invalid-argument-with-foreach/#findComment-986919 Share on other sites More sharing options...
Stephen Posted January 2, 2010 Share Posted January 2, 2010 See what happens when you do (instead of the foreach): print_r($_POST['manager']); Quote Link to comment https://forums.phpfreaks.com/topic/186883-help-with-invalid-argument-with-foreach/#findComment-986922 Share on other sites More sharing options...
msaz87 Posted January 2, 2010 Author Share Posted January 2, 2010 See what happens when you do (instead of the foreach): print_r($_POST['manager']); It spits out only one value... so it would seem teamatomic is correct in that it isn't an array -- any ideas what I'm doing wrong? Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/186883-help-with-invalid-argument-with-foreach/#findComment-986938 Share on other sites More sharing options...
msaz87 Posted January 2, 2010 Author Share Posted January 2, 2010 I was able to resolve the problem by simply changing the name of the select field... I'm not entirely certain why that made a difference -- must be something elsewhere in my code. Thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/186883-help-with-invalid-argument-with-foreach/#findComment-987006 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.