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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:57:14+00:00 2026-06-15T14:57:14+00:00

I am having trouble with a mini shopping cart. I have created the mini

  • 0

I am having trouble with a mini shopping cart. I have created the mini shopping cart and when a product is added it goes into the Basket page. However, i want to create a checkout page. How do i grab the products in the basket and put it in a checkout page.

So For example, the check out page will look like this

ITEM NAME, ITEM MODEL, ITEM PRICE

                 TOTAL OF ITEMS

CHECKOUT BUTTON (links to a payment system)

This is my Basket.php code:

<?php
    $bikecode = $_GET['id'];     //the product id from the URL 
    $action = $_GET['action']; //the action from the URL

if($bikecode && !productExists($bikecode)) {
    die("Product Doesn't Exist");
} 

    switch($action) {   //decide what to do 

        case "add":
            $_SESSION['cart'][$bikecode]++; //add one to the quantity of the product with id $bikecode 
        break;

        case "remove":
            $_SESSION['cart'][$bikecode]--; //remove one from the quantity of the product with id $bikecode 
            if($_SESSION['cart'][$bikecode] == 0) unset($_SESSION['cart'][$bikecode]); //if the quantity is zero, remove it completely (using the 'unset' function) - otherwise is will show zero, then -1, -2 etc when the user keeps removing items. 
        break;

        case "empty":
            unset($_SESSION['cart']); //unset the whole cart, i.e. empty the cart. 
        break;
    }

    if($_SESSION['cart']){

        echo "<table width=\"100%\">";   

          foreach($_SESSION['cart'] as $bikecode => $quantity) { 
             $sql = sprintf("SELECT BikeCode, Model, Price FROM Bike WHERE BikeCode = '%s';", $bikecode);

                $result = mysqli_query($con, $sql);

                if(mysqli_num_rows($result) > 0) {

                    list($bikecode, $model, $price) = mysqli_fetch_row($result);    

                    $cost = $quantity * $price;
                    $total = $total + $cost;

                        echo "<tr><th>BikeCode:</th><th>Model:</th><th>Quantity:</th><th>Price:</th></tr>";
                        echo "<tr>";
                        echo "<td align=\"center\">$bikecode</td>";
                        echo "<td align=\"center\">$model</td>";
                        echo "<td align=\"center\">$quantity <a href=\"$_SERVER[PHP_SELF]?action=remove&id=$bikecode\">X</a></td>";
                        echo "<td align=\"center\">£$cost</td>";
                    echo "</tr>";
                }
            }

            echo "<tr>";
                echo "<td colspan=\"3\" align=\"right\">Total</td>";
                echo "<td align=\"right\">£$total</td>";
            echo "</tr>";

            echo "<tr>";
                echo "<td colspan=\"4\" align=\"right\"><a href=\"$_SERVER[PHP_SELF]?action=empty\" onclick=\"return confirm('Are you sure?');\">Empty Cart</a></td>";
            echo "</tr>";       
        echo "</table>";

    }else{
        echo "You have no items in your shopping cart.";
    }

function productExists($bikecode) {
    $sql = sprintf("SELECT * FROM Bike WHERE BikeCode = '%s';", $bikecode); 
    return mysqli_num_rows(mysqli_query($con, $sql)) > 0;
}
?>
  • 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-06-15T14:57:15+00:00Added an answer on June 15, 2026 at 2:57 pm

    As long as you have a session_start(); on top of every page you should be able to use the exact same foreach loop as you do in this piece of coding. The session with the information would just be carried over to the next page.

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

Sidebar

Related Questions

Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
I'm having some trouble implementing DoubleBuffer into my program. Before you faint from the
Having trouble with selectors/transversing. Basically, I want the popup div to open when the
Having trouble with some select statements. I have 2 tables. sms_log and sms_messages. sms_log
Having trouble with Codekit/Compass. Know lots of people have had issues with this but
Having trouble grouping active forum sum results by wildcards. Ultimately, I want all the
Having trouble to start a new activity after progressbar have loaded. Im getting stucked
Having trouble trying to turn an XDocument into an list of objects, in particular
Having trouble using Powershell to manipulate IP Restrictions on IIsWebVirtualDir (Virtual Directories). However, i
I'm learning Java am having trouble running an example program. I have two files:

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.