Cart with Mysql - PHP

Discussion in 'PHP' started by leony, Aug 2, 2008.

  1. #1
    Hi,

    I have a question about my shopping cart. The cart and session variable are stored in mysql database. I have the following code structure:

    
    //basically no html in these include files. Purely GET -POST stuff //and mysql queries //etc.
    if(isset($_POST['add'])){
    include('addtocart.php'); 
    include('viewcart.php'); 
    
    }
    elseif(isset($_POST['update'])){
    include('updatecart.php'); 
    include('viewcart.php'); 
    }
    elseif(isset($_GET['pid'])){//delete item
    $pid=$_GET['pid'];
    include('deletecart.php'); 
    include('viewcart.php'); 
    }
    else{
    include('viewcart.php'); 
    }
    .
    .
    .
    //html and cart content is displayed...  
    
    PHP:
    My question is: Whenever I refresh the page whilst there are items in the cart, the quantity gets doubled. How can I prevent that? (I believe the code directly executes the following part:

    
    if(isset($_POST['add'])){
    include('addtocart.php'); 
    include('viewcart.php'); 
    }  
    
    PHP:

     
    leony, Aug 2, 2008 IP
  2. selling vcc

    selling vcc Peon

    Messages:
    361
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    after adding an item to the cart, redirect the user the the page you want... in order to loose the post data
     
    selling vcc, Aug 2, 2008 IP