Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2

Thread: basket

  1. #1
    New Coder
    Join Date
    May 2011
    Thanked 0 Times in 0 Posts



    // 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"];

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Thanked 637 Times in 625 Posts
    Pretty evident, those 4 variables don't exist.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts