Jump to content

Empty cart contents when user logs out


djlfreak

Recommended Posts

How do I word this function so the cart contents are emptied when user clicks log out button? I'm thinking it would be something like WHERE user_id= $_SESSION[''];

 

 

function deleteAbandonedCart() 
{ 

    $sql = "DELETE FROM tbl_cart 
            WHERE ??????   '"; 
    dbQuery($sql);         
} 

?>  

 

 

//LOGOUT FUNCTION 
        case 'Logout': 
        session_start(); 
        session_unset(); 
        session_destroy(); 
        redirect('index.php'); 
        break;  

 

Thanks in advance for any help  :D

 

Last post I promise, just trying to finish off website and had a few issues can't fix.

Link to comment
Share on other sites

I store cart contents in session id like this

// current session id
$sid = session_id();

// check if the product is already
// in cart table for this session
$sql = "SELECT pd_id
        FROM tbl_cart
		WHERE pd_id = $productId AND ct_session_id = '$sid'";
$result = dbQuery($sql);

At the moment it deletes cart entries older than one day but I want them to delete immediately once user leaves site, not logs out as you can shop without logging in. How would I achieve this?

/*
Delete all cart entries older than one day
*/
function deleteAbandonedCart()
{
$yesterday = date('Y-m-d H:i:s', mktime(0,0,0, date('m'), date('d') - 1, date('Y')));
$sql = "DELETE FROM tbl_cart
        WHERE ct_date < '$yesterday'";
dbQuery($sql);		
}

The reason I'm asking is when I was testing it logging in as different users the cart from old user was still there.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.