Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Grace Kelly
Grace Kelly
33,990 Points

Shopping Cart - Store Data in Session or Database?

hey guys i'm making an e-commerce site using php and mysql and i want to know how i should proceed when it comes to the shopping cart. I want to have it in such a way that if the user is logged in and they add items to the cart and then logout, the items will stay in the cart for when they log back in again....will a session suffice for this or do i need to create a table and store this data inside it??

2 Answers

You need to use a database. When the user logs out the session is lost, so you will lose the cart contents.

it would be best to store it in db if you are not using a 3rd party shopping cart.