I am trying to create a shopping cart for a website that sells one-of-a-kind jewelry.
I am trying to figure out a way to prevent 2 users simultaniously trying to purchase the same peice of jewelry, ie. if user A logs on and puts a certain peice in their cart, and then user B trys to put that same peice in their cart. Since only one of each peice exists, that can pose a problem.
I created a field in the table called "available" where it is set as 0 if the piece was purchased or put in someones cart. I need away to update that field as 1 if the user closes his/her session. It needs to be able to be full proof, and should not rely on the user pressing "logout" or something, ie, if the browser crashes, I want the peice showing as available. What is the best way to do this?