There is a copyright Point of Sale software for pharmacies in PHP. To prevent the cashier from selling more than the quantity of the product in stock, I do this:
include('../connect.php'); $nl = $_POST['nall'] ; $a = $_POST['invoice']; $b = $_POST['product']; $c = $_POST['qty']; if($c > $nl) { echo "<div align='center'><font color='red' style='font:bold 22px 'Aleo';'>Внимание: Вы не сможете расходовать больше чем остаток. Сейчас будете перенаправлены' </font> </div><br> "; echo "<meta http-equiv=\"refresh\" content=\"3;url=" . $_SERVER['HTTP_REFERER'] . "\">"; exit; } ?> As can be seen from the code, if the amount of the drug being sold (variable $ c) is MORE than the quantity in the warehouse (variable $ nl), then output an error. But if, for example, the amount of the drug in stock is 10 pcs. and the cashier is also going to sell 10 pcs., it still produces an error that you can not spend more than the remainder.
Question: How to write the condition correctly so that when the cashier is going to sell more, and not exactly - bring an error? I did it, and everything worked fine:
$result = $db->prepare("SELECT * FROM products WHERE product_id= :userid"); $result->bindParam(':userid', $b); $result->execute(); for($i=0; $row = $result->fetch(); $i++){ $nall= $row['qty'] ; if ($nall<$c) { echo "<div align='center'><font color='red' style='font:bold 22px 'Aleo';'>Внимание: Вы не сможете расходовать больше чем остаток. Сейчас будете перенаправлены' </font> </div><br> "; echo "<meta http-equiv=\"refresh\" content=\"2;url=" . $_SERVER['HTTP_REFERER'] . "\">"; exit; }