PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Sep 24, 2017 7:20 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Simple Shopping Cart
PostPosted: Thu Jul 03, 2008 10:43 pm 
Offline
Forum Newbie

Joined: Tue Jun 24, 2008 7:00 pm
Posts: 8
can u help in making a cart without database


Top
 Profile  
 
 Post subject: Re: Simple Shopping Cart
PostPosted: Thu Jul 03, 2008 10:55 pm 
Offline
Jack of Zircons
User avatar

Joined: Thu Nov 09, 2006 9:30 pm
Posts: 4484
Location: California, USA
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.


Top
 Profile  
 
 Post subject: Re: Simple Shopping Cart
PostPosted: Fri Jul 04, 2008 2:10 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13427
Location: New York, NY, US
You can just use sessions for the cart, but you will need to save the orders somewhere.

_________________
(#10850)


Top
 Profile  
 
 Post subject: Re: Simple Shopping Cart
PostPosted: Fri Jul 04, 2008 4:37 am 
Offline
Forum Newbie

Joined: Fri Jul 04, 2008 4:28 am
Posts: 1
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:
Syntax: [ Download ] [ Hide ]
<?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:
Syntax: [ Download ] [ Hide ]
<?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*/
}
?>


Last edited by John Cartwright on Fri Jul 04, 2008 4:53 am, edited 1 time in total.
Please use [code=php][/code] tags when posting code


Top
 Profile  
 
 Post subject: Re: Simple Shopping Cart
PostPosted: Mon May 08, 2017 2:14 am 
Offline
Forum Newbie

Joined: Mon May 08, 2017 2:08 am
Posts: 1
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?

_________________
Buy Sounds Like Home Furniture Online Australia.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Bing [Bot] and 15 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group