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 7008237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:42:32+00:00 2026-05-27T21:42:32+00:00

I am just learning the ropes of php and am building an e-commerce site

  • 0

I am just learning the ropes of php and am building an e-commerce site for a uni project, I have the whole thing built and setup payment via paypal, which I’ve done through a few tutorials.

When I am transferring to paypal I want to display; the item name, price and quantity for each item in the cart, within the order summary.

In its current state http://pastie.org/3127790 , the code is only displaying the top item in the cart in the order summary on paypal, I think I need to implement a foreach loop to tell the code to echo all rows in the cart, but am unsure what exactly to loop and how.

Any help would be greatly appreciated!

Thanks in advance, Michael

Code snippet

      <?php

        $sql = "SELECT * FROM podcasts WHERE id_podcasts IN (";
          foreach ($_SESSION['cart'] as $id => $value){
            $sql .= $id . ",";  
          }
          $sql = substr($sql,0,-1).") ORDER BY name ASC";
          $query = mysql_query($sql);
          $total_price = 0;
          if(!empty($query)){
          while($row = mysql_fetch_array($query)){
            $subtotal = $_SESSION['cart'][$row['id_podcasts']]['quantity']*$row['price'];
            $total_price += $subtotal;
            ?>

            <?php
            $ppname = $row['name'];
            $_SESSION['cart'][$row['id_podcasts']]['name'] = $row['name'];
            $ppquantity = $_SESSION['cart'][$row['id_podcasts']]['quantity'];
            $ppprice= $row['price'];
            ?>
              <tr>
                <td><?php echo $row['name'];?></td>
                <td><?php echo $_SESSION['cart'][$row['id_podcasts']]['quantity'];?></td>
                <td><?php echo "&pound;" . $row['price'];?></td>
                <td><?php echo"&pound;" .  $_SESSION['cart'][$row['id_podcasts']]['quantity']*$row['price'];?></td>
              </tr>
            <?php
          } }
          ?>


  <tr>
    <td></td>
    <td></td>
    <td><span>Total Price:</td></span>
    <td><span><?php echo"&pound;" .  $total_price;?></td></span>
  </tr>
</table>
</div>
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="payme_1321908135_biz@immbudden.com"> <!-- change to your paypal address -->
<input type="hidden" name="quantity" value="<?php echo $ppquantity;?>"> <!-- do not change, since you refer to it all via the database -->
<input type="hidden" name="item_name" value="<?php echo $ppname;?>">
<input type="hidden" name="amount" value="<?php echo $ppprice;?>"> <!-- change here -->
<input type="hidden" name="shipping" value="0.00">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="custom" value="<?php echo $_SESSION['emailaddress'];?>"> <!-- if you store their purchase in a database, reference the database number here -->
<input type="hidden" name="return" value="http://shop.residencyradio.com/success.php">
<span class="input_btn"><input type="submit" name="purchase" value="Purchase" ></span>
</form>
  • 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-27T21:42:33+00:00Added an answer on May 27, 2026 at 9:42 pm

    I only answer your question. I don’t sure about the effectiveness of all your code.
    I have made some changes in some of your pasted code:

    <?php
    $output_paypal = ''; // container for output for paypal form
    $total_items = 0;
    
    if ( ! empty($query))
    {
        while ($row = mysql_fetch_array($query))
        {
            $subtotal = $_SESSION['cart'][$row['id_podcasts']]['quantity'] * $row['price'];
            $total_price += $subtotal;
    
            $ppname = htmlspecialchars($row['name']);
            $_SESSION['cart'][$row['id_podcasts']]['name'] = $row['name']; // this assigment seems not useful
            $ppquantity = $_SESSION['cart'][$row['id_podcasts']]['quantity'];
            $ppprice = $row['price'];
    
            $total_items ++;
    
            $output_paypal .= <<<EOM
    <input type="hidden" name="item_name_{$total_items}" value="$ppname">
    <input type="hidden" name="quantity_{$total_items}" value="$ppquantity">
    <input type="hidden" name="amount_{$total_items}" value="$ppprice">
    EOM; // heredoc syntax (may not be any spaces or tabs before or after the semicolon.)
            ?>
            <tr>
                <td><?php echo $ppname; ?></td>
                <td><?php echo $ppquantity; ?></td>
                <td><?php echo "&pound;" . $ppprice; ?></td>
                <td><?php echo"&pound;" . $ppquantity * $ppprice; ?></td>
            </tr>
            <?php
        }
    }
    ?>
    
    
    <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
        <input type="hidden" name="cmd" value="_xclick">
        <input type="hidden" name="business" value="payme_1321908135_biz@immbudden.com">
    
        <?php echo $output_paypal; ?>
    
        <input type="hidden" name="shipping" value="0.00">
        <input type="hidden" name="currency_code" value="GBP">
        <input type="hidden" name="custom" value="<?php echo $_SESSION['emailaddress']; ?>">
        <input type="hidden" name="return" value="http://shop.residencyradio.com/success.php">
        <span class="input_btn"><input type="submit" name="purchase" value="Purchase" ></span>
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please bear with me, newbie just learning the ropes. I am getting the below
I'm just learning ruby on rails and I have a table of user roles
Just learning Silverlight 4/RIA and i 'm stuck in a weird problem: setup an
I'm just learning MVC3 now and this is really confusing me. I have a
I'm just learning Swing, and built a sample GUI for myself as practice. Very
Im just learning the ropes with javascript and jQuery but cant get my head
Just learning WPF databinding and have a gap in my understanding. I've seen a
I'm just learning the ropes on clearing floats for all browsers and had and
Just learning about sql joins and things, and I have a question. Can you
I'm just learning java and following a book. I have a program written via

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.