title: shopping cart in php with session & database
body: <p>I had developed a shopping cart in PHP using sessions and a database.</p>
  
  <p>If the user is not logged in (a guest), the cart items are stored in the <code>$_SESSION["cart"]</code> variable.</p>
  
  <p>If the user is logged in, all of the cart items from the <code>$_SESSION["cart"]</code> (if any) are copied to database and any previous cart items from database (if any) are also copied back to <code>$_SESSION["cart"]</code>. Here I'll keep the copies both in the session and the database.</p>
  
  <p>As long as user is logged in i don't have the problem with the cart items.</p>
  
  <p>Since I am using session for guests, I'll certainly lose the cart details as soon as browser is closed. </p>
  
  <p>How can I overcome this scenario?</p>
  
  <p>I am trying to store guest cart details in a database, with a unique cookie value. Suggestions please? cart Table Details :</p>
  
  <pre><code>cart_id*
  user_id
  product_id
  product_option_id
  product_count
  total_amount
  time_stamp
  
  user_id+product_id+product_option_id is Unique
  </code></pre>