-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadminStockUpdateProcess.php
More file actions
40 lines (33 loc) · 1.17 KB
/
adminStockUpdateProcess.php
File metadata and controls
40 lines (33 loc) · 1.17 KB
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
36
37
38
39
40
<?php
include "connection.php";
$productId = $_POST["p"];
$qty = $_POST["q"];
$price = $_POST["up"];
if (empty($qty)) {
echo ("Please Enter quantity");
} else if (!is_numeric($qty)) {
echo ("Only Numbers can be entered for Quantity");
} else if (strlen($qty) > 10) {
echo ("Quantity be less than 10 Characters");
} else if (empty($price)){
echo ("Please enter Unit Price");
} else if (!is_numeric($price)){
echo ("Only Numbers can be entered for Unit Price");
} else if (strlen($price) > 10){
echo ("Unit Price should be less than 10 Characters");
} else {
$rs = Database::search("SELECT * FROM `stock` WHERE `product_id` = '".$productId."' AND `price` = '".$price."'");
$num = $rs->num_rows;
$d = $rs->fetch_assoc();
if ($num == 1){
// Update Query
$newQty = $d["qty"] + $qty;
Database::iud("UPDATE `stock` SET `qty` = '".$newQty."' WHERE `stock_id` = '".$d["stock_id"]."'");
echo("success");
} else {
// Insert Query
Database::iud("INSERT INTO `stock` (`price`,`qty`,`product_id`) VALUES ('".$price."','".$qty."','".$productId."')");
echo ("New Stock Added Successfully");
}
}
?>