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
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unable to delete items in shopping cart

    Hi guys I am a bit lost with this. I have created this shopping cart script:


    PHP Code:
    <?php
    session_start
    ();
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    <?php
    echo "Your Shooping cart contains the following:";
    if(isset(
    $_POST['submit']))
    {
        
    $itemname $_POST['h1'];

        
    //echo $_SESSION['itemname'][$itemname];
        
    unset($_SESSION['itemqty'][$itemname]);
        unset(
    $_SESSION['itemprice'][$itemname]);
        unset(
    $_SESSION['itemname'][$itemname]);
    }

    echo 
    "<br/><br/>";
    echo 
    "<table border='1'>";
    echo 
    "<tr><th>Name</th><th>Quantity</th><th>Price</th></tr>";
    foreach(
    $_SESSION['itemname'] as $key=>$value)
    {

        echo
    '<tr><td>'.$_SESSION['itemname'][$key].'</td><td><input
    type="text" name="t1" value='
    .$_SESSION['itemqty'][$key].'></td><td>'.$_SESSION['itemprice'][$key].'</td><td>
    <form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete">
    <input type="hidden" name="h1" value='
    .$key.'></td></tr>';

    }




    echo 
    "</table>";

    ?>
    </body>
    </html>

    I however cannot delete items from the cart when viewing the cart. Any pointers?

  • #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
    As a general rule you should never name a submit button "submit". It causes problems. Name it "sub_btn" or "submit_button", but not "submit".

    This may or may not solve your problem.

    Did you verify (with an echo statement) your "if" condition is evaluating "true"?


  •  

    Posting Permissions

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