Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/224784-mysql-database-issue/
Share on other sites

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;
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.