I am using paypal to process payments on my site. Paypal returns the post array like
[item_number1] =12
[item_name1] = My product name
[quantity1] =3
[item_number2] =14
[item_name2] = My product name2
[quantity2] =5
[num_cart_items] 2
Insert step here now im just going in circles getting nowhere
And then run the for loop
for($i = 1;$i <= $num_cart_items ;$i++){
$x = 'item_number' . $i;
$y = 'item_name' . $i;
$z = 'quantity' . $i;
$new_amount = $row['stock_quantity'] - $$z;
$db->update1_by_match('cart_products','stock_quantity',$new_amount,'id',$$x);
}
Im having trouble with these variable variables. Is there a better way to do this?
Thanks
Andrew
I’d change your revised code to use $_POST directly, e.g.
The diagnostic output should help you refine where things are going for you.
EARLIER QUESTION – notes below refer to the question before a complete revision of it was it made.
What you really need is an array, rather than attempting to use variable variables
To do it the way you were doing it, something like this might clarify it
The $$varname is an example of a variable variable, but in your case an array declares your intent in a much clearer way.