Simple Shopping Cart
Posted: Thu Jul 03, 2008 10:43 pm
can u help in making a cart without database
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
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
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*/
}
?>