SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Old Fogey mancroft's Avatar
    Join Date
    Oct 2002
    Location
    lost
    Posts
    445
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cookie value not being set

    I am doing a shopping cart which was working OK until I put the instruction

    Code:
    //delete cookie
    setcookie("cartId");
    at the end of the email form which sends the email order to the shop.

    Now the value for the cookie has disappeared AND IT REFUSES TO SET A NEW COOKIE.

    I emptied the shopping cart AND cleared the cookies off the computer.

    The output to the code below is:

    Code:
    echo $sql;
     
    gives the output:
     
    insert into cart(cookieId, ITEMID, QTY,COLOR,SIZE) values ('', 1247001, 5, '' ,'')

    Any ideas please?



    Code:
     
    include("db.php");
    
    // Get a connection to the database
    $cxn = mysql_connect($dbServer, $dbUser, $dbPass, $dbName) or die
    (mysql_error()); 
    
    
    $db = mysql_select_db("oscart", $cxn)  or die(mysql_error()); 
    
    
    $sql = ("insert into cart(cookieId, ITEMID, QTY,COLOR,SIZE) values
    ('" . GetCartId() . "', $ITEMID, $QTY, '$COLOR' ,'$SIZE')") or die(mysql_error
    ());
    
    
    //look at sql
    echo $sql;
    
    
    ShowCart();
    :

    :

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What code do you use to create a cookie? Did it still not work after you deleted the cookie manually? Normally you delete a cookie with an emty value and a expire timestamp in the past.

  3. #3
    SitePoint Addict sleepingdanny's Avatar
    Join Date
    Oct 2002
    Location
    Israel
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Lets say you've created a cookie using the following code:

    Code:
    setcookie("cookie_name","cookie_value",time()+3600,"/","site.com");
    So, to delete the cookie we will use the next code:

    Code:
    setcookie("cookie_name","",time()-3600,"/","site.com");
    To delete a cookie you should use the cookie's name, time that already passed,
    and any other information that you used after the "time" - if you havn't used any, so don't
    use any when you delete the cookie.

    In your case, it looks like you'll need to use:

    Code:
    setcookie("cartId","",time()-3600);
    Hope that this helps.

    - Danny


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
  •