Jump to content

Help with invalid argument with foreach


msaz87

Recommended Posts

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.