Simple Shopping Cart
Moderator: General Moderators
-
chelflores
- Forum Newbie
- Posts: 8
- Joined: Tue Jun 24, 2008 7:00 pm
Simple Shopping Cart
can u help in making a cart without database
Re: Simple Shopping Cart
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.chelflores wrote:can u help in making a cart without database
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Simple Shopping Cart
You can just use sessions for the cart, but you will need to save the orders somewhere.
(#10850)
Re: Simple Shopping Cart
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:
And so far for the cart:
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");
}
}
?>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*/
}
?>
Last edited by John Cartwright on Fri Jul 04, 2008 4:53 am, edited 1 time in total.
Reason: Please use [code=php][/code] tags when posting code
Reason: Please use [code=php][/code] tags when posting code
-
Rainbowtide
- Forum Newbie
- Posts: 1
- Joined: Mon May 08, 2017 2:08 am
Re: Simple Shopping Cart
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.