charles724 Posted January 18, 2011 Share Posted January 18, 2011 I've been using MySql and PHP programming for about a year now. I searched this site to see if my question was answered before but could not find any information on the question that I have. Here it is: Someone asked me to design a site for them to sell there collectibles (i.e., comics, coins, & stamps). All of these items only have 1 available. He wants me to set up a shopping cart for customers to add what they want to buy to their shopping cart. My question is how do you prevent someone from adding an item when someone already has that one item in their cart already? For example, if customer A places Batman comic #500 in their cart and customer B comes along and wants to buy the same comic but there is only one available, what is the proper procedure to prevent this. Also, I don't want someone to have an item in their cart for, lets say, over an hour only not to make the purchase and then lose out to someone who really wants to buy the item. Does anyone know of a great example of this issue on the Internet? I hope I explained the issue enough. Thank you in advance. Quote Link to comment https://forums.phpfreaks.com/topic/224784-mysql-database-issue/ Share on other sites More sharing options...
QuickOldCar Posted January 18, 2011 Share Posted January 18, 2011 I would think you make a field name quantity and an amount of how many items in it for each item. In this case you say is only one Have a script checking mysql each time someone adds an item to their cart, change the 1 to 0 if they don't complete the transaction then place the quantity back to 1 I guess can use true or false as well mysql query... $quantity = $row['quantity']; if ($quantity < 1 ){ $stop_the_purchase = "some code to say is not available, don't let add to cart"; header('Location: /'); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/224784-mysql-database-issue/#findComment-1161150 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.