Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 475177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:21:44+00:00 2026-05-13T00:21:44+00:00

I am using paypal to process payments on my site. Paypal returns the post

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:21:44+00:00Added an answer on May 13, 2026 at 12:21 am

    I’d change your revised code to use $_POST directly, e.g.

    for($i = 1;$i <= $_POST['num_cart_items'] ;$i++){
    
       $item_number= intval($_POST['item_number' . $i]);
       $item_quantity= intval($_POST['quantity' . $i]);
    
       printf("DEBUG: item %d item:%d quantity:%d<br>", $i, $item_number, $item_quantity);
    
       $new_amount = $row['stock_quantity'] - $item_quantity;
       $db->update1_by_match('cart_products','stock_quantity',$new_amount,'id', $item_number);
    
    }
    

    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

    $item_numbers=array(24, 16);
    
    foreach ($item_numbers as $item_number) {
        $result = $db->get_cols_by_match('cart_products','stock_quantity','id', $item_number);
    }
    

    To do it the way you were doing it, something like this might clarify it

    $item_number1='24';
    $item_number2='16';
    $num_cart_items = 2
    
    for($i = 1;$i <= $num_cart_items ;$i++){                
        $varname='item_number' . $i;
        printf("DEBUG: %s = %s<br>", $varname, $$varname);
    
        $result = $db->get_cols_by_match('cart_products','stock_quantity','id', $$varname);
    }
    

    The $$varname is an example of a variable variable, but in your case an array declares your intent in a much clearer way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a PayPal IPN script to process subscription payments on my new project.
I am writing a java program to process direct payments using paypal. Naturally I
I'm using Paypal to handle automated recurring payments for my website. Users pay to
I have an website on asp.net-mvc, I'm thinking of using paypal for payments, is
I'm using Google App Engine to process Paypal IPN messages, when my servlet starts
I am using PayPal Website Payments Standard to accept payments on an online store.
I'm in the middle of developing an e-commerce site that is using Paypal as
I am new to Google App Engine (Java) and PayPal process. I am using
I am currently using PayPal's Website Payments Standard to accept credit cards on my
I am adding subscriptions to a site using Paypal IPN which works very well,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.