How can I add the data to shopping cart?

How do i add information to a session of shopping cart data into a database?

  • i have a shopping cart and i wanted to store the shopping cart information to my database but i have no idea how to do it since i have no way to detect how many items my customer would add to their shopping cart. What i have in mind right now would be having a non-unique key as shopping cart id. I.E ID / book / price / quantity 1/harry potter/19.90/1 1/deadly hollows/49.90/1 and both of id 1 will consitute as a complete shopping cart. Will there be something wrong with this way of doing?

  • Answer:

    A non-unique key is not a good solution. I would add an auto-increment key to the shopping cart table and use that as "real" unique key. Just keep your non-unique ID as it is, so you can use it as an OrderID to see which rows belong to the same order. Like this: UniqueID / OrderID / book / price / quantity 1/1/harry potter/19.90/1 2/1/deadly hollows/49.90/1 3/2/code complete/25.90/2

3cross at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

You should have a Primary Key that is unique, but can span multiple columns: You could probably use ID and book as your Primary Key, since each cart won't have 2 copies of the same book, because that would just update the quantity, not add a new row.

PaulP.R.O.

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.