Jump to content

Warning: Invalid argument supplied for foreach()


MasterACE14

Recommended Posts

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.

Link to comment
Share on other sites

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

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.