kimmyko
05-18-2011, 06:27 AM
<?php
session_start();
// 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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Basket</title>
<meta name="keywords" content="KEYWORDS" />
<meta name="description" content="DESCRIPTION" />
<meta name="copyright" content="Tiram © 2005" />
<link rel="stylesheet" href="default.css" type="text/css" media="all" title="Default styles" />
</head>
<h1>View your basket</h1>
<p>
<a href="DisplayDresses.php">Continue Shopping</a>
<a href="Checkout.php">Checkout</a>
</p>
<h2>Your basket items...</h2>
<table with="50%" BORDER="1">
<tr><th>Id</th><th>Name</th><th>Price</th><th>Qty</th></tr>
<?php
$Total =0;
// Get each item in the basket
foreach ( $basket as $item )
{
// Get the id, name,price and qty from the item
$id=$item["id"];
$name=$item["name"];
$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";
?>
</table>
<h3>Your basket contains $nItems different item(s).</h3>
<a href="DisplayDresses.php">Continue shopping</a>
</body>
</html>
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"];
session_start();
// 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"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Basket</title>
<meta name="keywords" content="KEYWORDS" />
<meta name="description" content="DESCRIPTION" />
<meta name="copyright" content="Tiram © 2005" />
<link rel="stylesheet" href="default.css" type="text/css" media="all" title="Default styles" />
</head>
<h1>View your basket</h1>
<p>
<a href="DisplayDresses.php">Continue Shopping</a>
<a href="Checkout.php">Checkout</a>
</p>
<h2>Your basket items...</h2>
<table with="50%" BORDER="1">
<tr><th>Id</th><th>Name</th><th>Price</th><th>Qty</th></tr>
<?php
$Total =0;
// Get each item in the basket
foreach ( $basket as $item )
{
// Get the id, name,price and qty from the item
$id=$item["id"];
$name=$item["name"];
$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";
?>
</table>
<h3>Your basket contains $nItems different item(s).</h3>
<a href="DisplayDresses.php">Continue shopping</a>
</body>
</html>
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"];