can anyone help me?
thanks in advance
cart.php
<?php
session_start ();
//session_destroy ();
$page = 'index.php';
include 'db.php';
/*
if ( !isset( $_SESSION['cart'] ) ) {
$_SESSION['cart'] = array();
}
*/
//add
if (isset ($_GET['add']))
{
$stock = mysql_query('SELECT itemID, stock FROM items WHERE itemID ='.mysql_real_escape_string((int)$_GET['add']));
while ($stock_row =mysql_fetch_assoc($stock))
{
if ($stock_row ['stock']!=$_SESSION ['cart_'.(int)$_GET ['add']])
{
$_SESSION ['cart_'.(int)$_GET['add']]+='1';
}
}
header ('Location: ' .$page);
}
//remove
if (isset ($_GET['remove']))
{
$_SESSION ['cart_'.(int)$_GET ['remove']]--;
header ('Location: ' .$page);
}
//delete
if (isset ($_GET['delete']))
{
$_SESSION ['cart_'.(int)$_GET ['delete']]='0';
header ('Location: ' .$page);
}
function items ()
{
$get = mysql_query ('SELECT itemID, name, description, price FROM items WHERE stock > 0 ORDER by itemID DESC');
if (mysql_num_rows ($get)== 0)
{
echo "Item is out of stock";
}
else
{
while ($get_row = mysql_fetch_assoc($get))
{
echo '<h1>' .$get_row ['name'].'</h1>';
echo '<p>' .$get_row ['description'].'<br/>£' .number_format($get_row ['price'], 2).' <a href="cart.php?add='.$get_row['itemID'].'">Add to basket</a> </p>';
}
}
}
/*
function order()
{
$num =0;
foreach ($_SESSION as $name => $value)
{
if ($value !=0)
{
if (substr($name, 0, 5)=='cart_')
{
$itemID = substr ($name, 5, strlen($name)-5);
$get = mysql_query ('SELECT itemID, name, price FROM items WHERE stock > 0 ORDER by itemID DESC');
while ($get_row = mysql_fetch_assoc ($get))
{
$num++;
}
}
}
}
}
*/
function cart()
{
//$_SESSION['cart'] = true;
foreach ($_SESSION as $name => $value)
{
if ($value > 0)
{
if (substr($name, 0, 5)=='cart_')
{
$itemID = substr($name, 5, (strlen($name)-5)); //removes cart_ on display
$get =mysql_query ('SELECT itemID, name, price FROM items WHERE itemID='.mysql_real_escape_string((int)$itemID));
while ($get_row = mysql_fetch_assoc ($get))
{
$sub = $get_row ['price']* $value;
echo $get_row ['name']. 'x' .$value. '@ £' .number_format($get_row['price'], 2). '=£' .number_format($sub, 2). '<a href="cart.php?remove='.$itemID.'">[-]</a> <a href="cart.php?add='.$itemID.'">[+]</a> <a href="cart.php?delete='.$itemID.'">[Delete]</a><br/>';
}
}
$total =+ $sub;
}
}
if ($total==0)
{
echo "Your cart is empty";
}
else
{
echo 'Your total is £ ' .number_format($total, 2);
//checkout button
}
}
function orders()
{
$num=0;
foreach ($_SESSION as $name => $value)
{
if ($value > 0)
{
if (substr($name, 0, 5)=='cart_')
{
$itemID = substr($name, 5, (strlen($name)-5)); //removes cart_ on display
$get =mysql_query ('SELECT itemID, name, price FROM items WHERE itemID='.mysql_real_escape_string((int)$itemID));
while ($get_row = mysql_fetch_assoc ($get))
{
$sub = $get_row ['price']* $value;
echo $get_row ['name']. 'x' .$value. '@ £' .number_format($get_row['price'], 2). '=£' .number_format($sub, 2);
echo'<input type="hidden" name="item_num_'.$num.'" value="'.$itemID.'">';
echo'<input type="hidden" name="item_nam_'.$num.'" value="'.$get_row['name'].'">';
echo'<input type="hidden" name="amount'.$num.'" value="'.$get_row['price'].'">';
echo'<input type="hidden" name="item_quantity'.$num.'" value="'.$value.'">';
$order[$itemID]= $value;
while(list($key, $value)= each($order)){
echo"$key; $value";
}
$num++;
}
}
}
}
}
if ($total==0)
{
echo "Your cart is empty";
}
else
{
echo 'Your total is £ ' .number_format($total, 2);
//checkout button
}
}
?>

New Topic/Question
Reply



MultiQuote




|