-
Notifications
You must be signed in to change notification settings - Fork 0
/
sale_succes.php
35 lines (32 loc) · 953 Bytes
/
sale_succes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
$pid =(int) ($_POST['pname']);
$demand = $_POST['quantity'];
$store = (int)($_POST['store']);
$con=mysqli_connect("localhost","root","root","warehouse");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = "SELECT * FROM central_storage WHERE value=1 and product_ID=pid ORDER BY t_stamp";
$result = mysqli_query($con,$sql);
while($demand>0){
$rows = mysqli_fetch_array($result);
if($demand >= $rows['quantity']){
$demand = $demand - $rows['quantity'];
$sql2 = "UPDATE central_storage SET quantity=0 and valid=0 WHERE ID=$rows['ID']";
}
else{
$new_quantity = $rows['quantity']-$demand;
$sql2 = "UPDATE central_storage SET quantity=$new_quantity WHERE ID=$rows['ID']";
$demand = 0;
}
if (mysqli_query($con,$sql2)){
echo "Data updated successfully <br/>";
}
else{
echo "Error updating data " . mysqli_error($con);
}
}
mysqli_close($con);
?>