Jump to content

[SOLVED] Array, foreach and checkboxes.


zero118

Recommended Posts

I keep getting an invalid foreach argument here...

 

 

			case 'move_loc':
				foreach ($_POST[ 'move' ] as $key )
				{
					$update ("UPDATE recert SET location =" . $_POST[ 'location' ] . " WHERE serial =
'$key'");			
				}
			break;

 

 

My form uses 'move' as the checkbox names and I am attempting to update multiple rows at one time.  I do not have much experience with foreach so any help is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/161862-solved-array-foreach-and-checkboxes/
Share on other sites

If the operand is not an arrray, then you're going to have an issue with foreach.  Under certain circumstances your $_POST['move'] probably either doesn't exist at all or isn't an array.  My recommendation for a quick examination of this is to use print_r() on the $_POST['move'] variable to understand what's happening better.

Be careful, cause you may want the value of each element of the array rather than the key.  You can obtain the value by adding this to your foreach loop:

 

foreach ($_POST['move'] as $key => $value)

 

NOTE - Click "topic solved" bottom left.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.