SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2006
    Posts
    145
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Add to basket script not working for a minority

    Hi there

    I have a problem which is being experienced by some customers but I can't replicate it myself so I'm a bit stuck as to what is happening. Any help would be much appreciated. Here is the problem....

    I have an ecommerce website and next to each product is a BUY button which POSTs to addtobasket.php, which contains something like this:
    PHP Code:
    $ref HTTP_SERVER.$_SESSION['ref'];
    $prodid $_POST['pid'];
    $qty $_POST['qty'];

    if(
    $prodid) {
        if(!isset(
    $_COOKIE["babasketid"])) {
            
    // See CartOP.php
            
    $basketid generateBasketId();
            
    setcookie("babasketid"$basketidtime()+43200);  /* expire in 12 hours */
        
    } else {
            
    $basketid $_COOKIE["babasketid"];
        }
        
        
    addProductToBasket($basketid$prodid$qty);
    }

    // Redirect to whereever they came from
    header("Location:$ref");
    exit; 
    So the script will take the POSTed product ID and quantity and add the item to the customers basket which is stored in a mysql database. It will then redirect the user back to whatever page they came from (tracked in the session).

    This has always worked absolutely fine for me, but the odd user complains that when clicking the busy button that nothing happens. They are just redirected back to the page without anything being added to the basket.

    Apparantly they haven't disabled cookies so that doesn't appear to be the issue.

    Any ideas?

    Many thanks

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try debugging:
    PHP Code:
    <?php
    ini_set
    ("display_errors"1);
    error_reporting(E_ALL);
    session_start();
    print_r($_SESSION);
    print_r($_POST);
    print_r($_COOKIE);

    define("HTTP_SERVER""http://www.exdomain.com");

    $ref HTTP_SERVER $_SESSION['ref'];

    $prodid $_POST['pid'];
    $qty $_POST['qty'];

    if (
    $prodid)
    {
        if (! isset(
    $_COOKIE["babasketid"]))
        {
            
    // See CartOP.php
            
    $basketid generateBasketId();
            
    setcookie("babasketid"$basketidtime() + 43200);
             
    /* expire in 12 hours */
        
    }
        else
        {
            
    $basketid $_COOKIE['babasketid'];
        }
        
    addProductToBasket($basketid$prodid$qty);
    }

    // disable header location for testing

    // header("Location: $ref");

    ?>
    my mobile portal
    ghiris.ro

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Nobody is saying anything, so heres my 2c.

    1. Did you see what happens if you turn JS off?

    2. Get addProductToBasket() to log the data somewhere, or upon failing, log the data.

    OR

    see what addProductToBasket() returns on success, maybe it returns true, so you can do;

    if( !addProductToBasket($basketid, $prodid, $qty) ){
    // log the bad data

    }

    3. Check that $_COOKIE["babasketid"] is being frisked somewhere along the line, else you will be open to sql injection attacks.

    actually, thats 3c
    Last edited by Cups; Apr 7, 2009 at 07:10. Reason: Oh, well thats two replies you have


Bookmarks

Posting Permissions

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