View Full Version : basket

05-18-2011, 07:27 AM

// Declare basket if not already declared
if ( ! isset($_SESSION ["basket"] ))
$basket = array();
$_SESSION["basket"] = $basket;

// Copy the session to local variable
$basket= $_SESSION["basket"];

// Get the id, name, price,and qty from command line
$id = $_REQUEST["hidId"];
$name = $_REQUEST["hidName"];
$price = $_REQUEST["hidPrice"];
$qty = $_REQUEST["txtQty"];

// Form them into an aray and add to basket
$item = array("id"=>$id,"name"=>$name,"price"=>$price,"qty"=>$qty);
$basket[] = $item;

// Update the SESSION array
$_SESSION["basket"] = $basket;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<meta name="keywords" content="KEYWORDS" />
<meta name="description" content="DESCRIPTION" />
<meta name="copyright" content="Tiram &copy; 2005" />
<link rel="stylesheet" href="default.css" type="text/css" media="all" title="Default styles" />


<h1>View your basket</h1>

<a href="DisplayDresses.php">Continue Shopping</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="Checkout.php">Checkout</a>

<h2>Your basket items...</h2>
<table with="50%" BORDER="1">


$Total =0;

// Get each item in the basket
foreach ( $basket as $item )

// Get the id, name,price and qty from the item
$price = $item["price"];
$qty = $item["qty"];

// Write a table row
echo "<tr><td>$id</td<td>$name</td><td>$price</td><td>$qty</td</tr>\n";

// Accumulate the total
$item = $price * $qty;
$total = $total + $item;


// Finally write the total
echo "<tr><td>Total</td><td>$total</td></tr>\n";

<h3>Your basket contains $nItems different item(s).</h3>

<a href="DisplayDresses.php">Continue shopping</a>

when i run my shopping basket i get these errors

Notice: Undefined index: hidId in G:\webclient\xampp\htdocs\Mywebsite\basket.php on line 15

Notice: Undefined index: hidName in G:\webclient\xampp\htdocs\Mywebsite\basket.php on line 16

Notice: Undefined index: hidPrice in G:\webclient\xampp\htdocs\Mywebsite\basket.php on line 17

Notice: Undefined index: txtQty in G:\webclient\xampp\htdocs\Mywebsite\basket.php on line 18

these are lines 15-18
$id = $_REQUEST["hidId"];
$name = $_REQUEST["hidName"];
$price = $_REQUEST["hidPrice"];
$qty = $_REQUEST["txtQty"];

05-18-2011, 04:00 PM
Pretty evident, those 4 variables don't exist.