MasterACE14 Posted August 22, 2010 Share Posted August 22, 2010 I have the following code: if ( !empty($_GET['quantity']) ) { foreach ( $_GET['quantity'] as $order_code => $quantity ) { // line 13 $Cart->setItemQuantity($order_code, $quantity); } } and I'm getting the following error: Warning: Invalid argument supplied for foreach() in shopping-cart/cart_action.php on line 13 $_GET['quantity']; has a value of '1' The code is working perfectly fine on localhost, but throws me that warning on my webserver(both have error reporting set to E_ALL) any help is greatly appreciated. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/211417-warning-invalid-argument-supplied-for-foreach/ Share on other sites More sharing options...
sasa Posted August 22, 2010 Share Posted August 22, 2010 can you post your form code Quote Link to comment https://forums.phpfreaks.com/topic/211417-warning-invalid-argument-supplied-for-foreach/#findComment-1102320 Share on other sites More sharing options...
Tazerenix Posted August 22, 2010 Share Posted August 22, 2010 if $_GET['quantity'] has a value of '1' then its not an array type, which means that a foreach loop can't execute on it. Quote Link to comment https://forums.phpfreaks.com/topic/211417-warning-invalid-argument-supplied-for-foreach/#findComment-1102330 Share on other sites More sharing options...
MasterACE14 Posted August 22, 2010 Author Share Posted August 22, 2010 can you post your form code <form class="cart_form" action="plugins/shopping-cart/cart_action.php" method="get"> <input type="hidden" name="order_code" value="Sword" /> <label>Sword: <input class="center" type="text" name="quantity" value="1" size="3" /> </label> <input type="hidden" name="TB_iframe" value="true" /> <input type="hidden" name="height" value="400" /> <input type="hidden" name="width" value="780" /> <input type="submit" name="submit" value="Add to cart" /> </form> if $_GET['quantity'] has a value of '1' then its not an array type, which means that a foreach loop can't execute on it. ok that makes sense, but why would it work locally and not on the webserver? they're both PHP 5? :S Quote Link to comment https://forums.phpfreaks.com/topic/211417-warning-invalid-argument-supplied-for-foreach/#findComment-1102331 Share on other sites More sharing options...
trq Posted August 22, 2010 Share Posted August 22, 2010 why would it work locally and not on the webserver? they're both PHP 5? :S One has more verbose error reporting is all. Neither would work, but only one seems to be displaying the warning. Quote Link to comment https://forums.phpfreaks.com/topic/211417-warning-invalid-argument-supplied-for-foreach/#findComment-1102336 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.