I have read about REPLACE and INSERT ON DUPLICATE key queries, and while I can see how useful they are, they don't appear to work for my purposes. Perhaps my database design is off from how it should be, but either way I hope I can get this working.
I am trying to mock up an online store to teach myself mysql and php, and I am recording a session id for use in pulling an individual's cart back for an individual visit and attempting to write inventory to the cart where I'm having an issue is in trying to check if the item is in the cart or not. I want each item to be unique per user, however it should not be unique for the entire table, or else this would prevent the multiple users from buying the same item, wouldn't it?
My table so far looks like this:
| Cart ID(key) | USER_ID(fk) | ItemNum | ItemQTY |
and I essentially want to see if a USER_ID already has > 0 ItemQTY of ItemNum in their cart. If they do I would like itemQTY to update to itemQTY + however many they add, and if not, then insert a new line.
Will I have to query before I write in order to do this?