Page 1 of 1

Simple Shopping Cart

Posted: Thu Jul 03, 2008 10:43 pm
by chelflores
can u help in making a cart without database

Re: Simple Shopping Cart

Posted: Thu Jul 03, 2008 10:55 pm
by califdon
chelflores wrote:can u help in making a cart without database
If you will post the code you've written so far, and tell us which parts don't work, we should be able to offer some suggestions.

Re: Simple Shopping Cart

Posted: Fri Jul 04, 2008 2:10 am
by Christopher
You can just use sessions for the cart, but you will need to save the orders somewhere.

Re: Simple Shopping Cart

Posted: Fri Jul 04, 2008 4:37 am
by Becca
Since I'm having a similar issue, I'll post my inquiry in here rather than starting a new thread.

I'm trying to do a simple shopping cart for a Basic PHP class. It consists of three main pages - the login page, the product page, and the shopping cart. The items can be passed through the URL to the shopping cart, or the information is to be passed through $_SESSION. Either way, the user needs to be able to add more items to the shopping cart (we don't have to worry about ability to delete them).

I'm having no issues with the login page, that's working fine. The problem that I'm having is moving items from the product page to the shopping cart. I think the issue I'm having is how to display the $_GET array.

I'm currently trying to pass the information in the URL, but if someone could walk me through passing it in the $_Session (especially if that's easier for adding multiple items) it would be greatly appreciated.

Here's the information for the Product page:

Code: Select all

<?php
session_start();
/*  Program name: furniture.php 
 *  Description:  Displays selected furniture category
 */
ini_set("display_errors","on");
error_reporting(E_ALL | E_STRICT);
ini_set("include_path","./supportfiles");
/*Test if user logged in, if not, return to loginpage*/
if(!isset($_SESSION['auth']) or $_SESSION['auth'] != "yes")
{
    header("location: login.php");
    exit();
}
else
{
    /*Test to see whether category button was clicked*/
    if(isset($_POST['cat_select']) and $_POST['cat_select'] == "yes")
    {   
        include("cat_select.inc");
            
        /*Check the Database for all items within that category*/
        $sql = "SELECT * FROM $tablename WHERE Category='$_POST[Category]'";
        $result = mysqli_query($cxn,$sql)
             or die ("Couldn't execute query.");
             
        /*Run a while loop that displays each item found by the inquiry*/
        echo "<table border='1' cellpadding='5'><tr>";
        while($row = mysqli_fetch_assoc($result))
        {
            extract($row);
            echo "<td><img src='$ImgURL'><br />";
            echo "$ItemName <br />";
            echo "$ItemDesc <br />";
            echo "$ $Price <br /><a href='cart.php?ItemID=$ItemID'>Buy Me!</a></td>";
        }
        echo "</tr></table>";
        exit();
    }
    
    /*If nothing else, include Category selection*/
    else
    {
        include("cat_select.inc");
    }
}
?>
And so far for the cart:

Code: Select all

<?php
session_start();
/*  Program name: cart.php 
 *  Description:  Displays shopping cart
 */
ini_set("display_errors","on");
error_reporting(E_ALL | E_STRICT);
ini_set("include_path","./supportfiles");
include("dbinfo_test.inc");
$cxn = mysqli_connect($host,$user,$passwd,$dbname)
         or die ("couldn't connect to server");
$tablename = "furniturestore";
 
$items = array($_GET['ItemID']);
 
/*Test if user logged in, if not, return to loginpage*/
if(!isset($_SESSION['auth']) or $_SESSION['auth'] != "yes")
{
    header("location: login.php");
    exit();
}
 
else
{
    /*If there are no items in the cart, provide a link to go back to the catalog*/
    if(@sizeof($items = 0))
    {
        echo "There are no items currently in your cart<br /><a href='furniture.php'>Click here to continue shopping</a>";
    }
    else
    {
        /*If there are items already in the cart, display them here*/
        echo "<table>";
        foreach($items as $_GET['ItemID'])
        {
            $sql = "SELECT * FROM $tablename WHERE ItemID='$_SESSION[ItemID]'";
            $result = mysqli_query($cxn,$sql)
                 or die ("Couldn't execute query.");
            echo "<tr><td>$items</td></tr>";
        }
        echo "</table>";
    }
    /*Function to sum up all items in cart*/
}
?>

Re: Simple Shopping Cart

Posted: Mon May 08, 2017 2:14 am
by Rainbowtide
Hi, this is really strange to have a shopping cart without database. I am new here from Sydney, Australia and looking for a simple cart for my furniture section only! Possible?