SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Philadelphia
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unable to destroy object

    I have a shopping cart object.
    This script is from my "success" page, where the user has successfully placed order, I show them summary, and then it's supposed to destroy their cart.

    Problem is, when they go to other pages in the site, the objects still exist and there are still things in the cart.

    PHP Code:
    <?php

    echo "Here is your order. You may want to print out this page.";
    $cart=($_SESSION['cart']);
    $showcart=$cart->displaycartdone();
    mail("[email="me@mydomain.com"]me@mydomain.com[/email]""order","$showcart");
     
     
    //if they've reached this page, we can dump their cart//

    unset($cart);
    ?>
    Not working. Why?
    I tried
    unset($_SESSION['cart']); and that does not seem to work either.

  2. #2
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    How do you mean it's not working? More information please

  3. #3
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Philadelphia
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    as i said above:
    "Problem is, when they go to other pages in the site, the object still exists because and there are still things in the cart."

    My shopping cart object is storing the elements that they have in their cart.

  4. #4
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    That way I would do it would be instead of destroying the object, just have a method within the object to delete the contents of that cart. However what you're doing should work. Are you sending any cache headers to the browser? After the cart is supposed to be deleted, try hitting Refresh a couple of times and see if that helps.

  5. #5
    SitePoint Wizard
    Join Date
    May 2003
    Location
    Berlin, Germany
    Posts
    1,829
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    unset($cart); 
    of course won't work as you only dump a copy of the $_SESSION['cart'] variable, which is the one that is remembered. Try this instead:

    PHP Code:
    $cart &= $_SESSION['cart']; 
    Now try dumping $cart. by the way, why do you have brackets around $_SESSION['cart'] when you assign it to $cart?

    If you do not need any other session info you might as well want to destroy the session? ( session_destroy() )

    Hope this helps.

  6. #6
    SitePoint Addict
    Join Date
    Dec 2002
    Location
    Philadelphia
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all the input. This forum rocks.

    Actually I feel bad... the code above would have worked....EXCEPT I forgot I had written a function in my shoppingcart class that looks in the user profile and sees if they have any stored cart objects and automatically remembers any cart they had.

    So I just wrote a function to go into the user account and delete the stored objects in the SUCCESS! page and now the above code works.

    But the above input you all have given has been helpful... always good to learn from this forum.


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
  •