Imagine that the buyer added three modems to the cart, and started browsing the site further. And after a while, when he decided to place an order, the “In Stock” modems became 2 pcs (one modem was bought by someone else). And in his basket 3 modems are hanging, now he will be able to place an order for 3 modems. And then in the “Available” field the number will change to “-1 ″.

So that a person could not place an order for a larger quantity of goods than are in stock, you should always after the user clicks the “Checkout” button do a check for consistency: The number of goods indicated in the basket should not exceed the number specified in the field “In stock” regarding one product. If it exceeds, then issue a message: “Such (to indicate here what kind of goods) goods in stock: n pieces. Please change the number of goods in the field of the same name and click “recalculate”.

Basically, I understood how to do it, after pressing the button, we have to place an order, call the database to compare the count. goods in stock and the quantity in the basket, if they> =, then the goods are cleared, if <=, then it displays a message that "litter blah blah blah", that's just in the code I can not write.

  • First, in my opinion, the approach is not entirely correct. Imagine that you in the store put three bottles of vodka in a basket and continue to defile in rows. At this time, Uncle Vasya comes from the "deli team", who has pipes burning and takes one bottle from you. Your reaction is a little bewilderment. Secondly, what exactly can you not write? - Deonis
  • The sample and comparison code cannot write the quantities in my basket and the quantity in the database - psix
  • Well, this is already done for you by Mr @Chavez below - Deonis

1 answer 1

$rate = $_POST['rate'];// получили количество товара, требуемое покупателю $artikul = $_POST['artikul']; // артикул(уникальный ID товара) $result = mysql_query("SELECT rate FROM sklad WHERE artikul='$artikul';");// выбрали из БД остаток конкретного товара на складе $a = mysql_fetch_array($result); if($rate>$a['rate']) echo "извините, осталось всего $a['rate'] наименования данного товара";