Complete deposit(). Add updated requirement function.

This commit is contained in:
Ceda EI 2018-07-01 14:57:59 +05:30
parent 269e45b653
commit a1fcc9dea9
1 changed files with 25 additions and 7 deletions

View File

@ -71,21 +71,39 @@ function add_requirement() {
function deposit(){
global $command_list;
$item_id = $command_list[1];
for ($i = 2; $i < count($command_list) - 1; $i++){
$item_name .= $command_list[$i];
if ($i != count($command_list) - 2){
$item_name .= " ";
}
}
$quantity = $command_list[count(command_list) - 1];
$quantity = $command_list[2];
$mysql = require('mysql_credentials.php');
$conn = new mysqli($mysql['servername'], $mysql['username'], $mysql['password'], $mysql['database']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$stmt = $conn->prepare("UPDATE req set quantity = quantity - ? where id = ?;");
$stmt->bind('is', $item_id, $quantity);
$stmt->execute();
$conn->close();
send_html("Deposited!");
}
function get_updated_req() {
$mysql = require('mysql_credentials.php');
$conn = new mysqli($mysql['servername'], $mysql['username'], $mysql['password'], $mysql['database']);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT name, quantity FROM req WHERE quantity > 0;";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$text = "";
while($row = $result->fetch_assoc()) {
$text .= $row["id"] . " " . $row["quantity"] . "\n";
}
return $text;
} else {
return "Everything is complete";
}
}
// Get JSON from post, store it and decode it.
$var = file_get_contents('php://input');
$decoded = json_decode($var);