Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    basket

    <?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 &copy; 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>&nbsp;&nbsp;&nbsp;&nbsp;
    <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"];

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    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
    •