zero118 Posted June 11, 2009 Share Posted June 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161862-solved-array-foreach-and-checkboxes/ Share on other sites More sharing options...
Maq Posted June 11, 2009 Share Posted June 11, 2009 Are you sure you're passing these values as arrays from your form. i.e. - Before your switch, try to print the array: print_r($_POST['move']); Quote Link to comment https://forums.phpfreaks.com/topic/161862-solved-array-foreach-and-checkboxes/#findComment-854001 Share on other sites More sharing options...
gizmola Posted June 11, 2009 Share Posted June 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161862-solved-array-foreach-and-checkboxes/#findComment-854002 Share on other sites More sharing options...
zero118 Posted June 11, 2009 Author Share Posted June 11, 2009 Yes, I can see the array just fine. But it is still telling me the argument is invalid. Could it have anything to do with the format of the contents? A sample would be FVRB-8239 Quote Link to comment https://forums.phpfreaks.com/topic/161862-solved-array-foreach-and-checkboxes/#findComment-854004 Share on other sites More sharing options...
zero118 Posted June 11, 2009 Author Share Posted June 11, 2009 I apologize, the error was elsewhere. Sometimes all you need is someone to make you look at the code a little harder =-) The array was fine, it was a query that was causing the issue. Quote Link to comment https://forums.phpfreaks.com/topic/161862-solved-array-foreach-and-checkboxes/#findComment-854005 Share on other sites More sharing options...
Maq Posted June 11, 2009 Share Posted June 11, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/161862-solved-array-foreach-and-checkboxes/#findComment-854006 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.