How can I use a database and PHP sessions to store a user’s shopping cart? I am using CodeIgniter, if that helps.
Example code would also be nice.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would write an add to basket function like this:
In this shopping basket function we save Product IDs in an session array.
Here is what I would have in the show basket function:
For each ProudctID in our session basket we make a SQL query to output product information.
Now last but not least, a clear basket function:
Don’t forget
session_start();before you add any Product IDs to your session basket. Also don’t forget themysql_connect();function, you need this before you make any queries with the database.