-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifyfood.php
33 lines (27 loc) · 872 Bytes
/
modifyfood.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
<?php
require_once('connect.php');
$foodId = $_POST['id'];
if($foodId) {
$name = $_POST['name'];
if($name != '') {
$db->prepare("UPDATE Food SET Name=? WHERE FoodID=?")->execute([$name, $foodId]);
}
$price = $_POST['price'];
if($price != '') {
$db->prepare("UPDATE Food SET Price=? WHERE FoodID=?")->execute([$price, $foodId]);
}
$categoryId = $_POST['categoryId'];
$db->prepare("UPDATE Food SET CategoryID=? WHERE FoodID=?")->execute([$categoryId, $foodId]);
}
else {
$name = $_POST['name'];
$price = $_POST['price'];
$categoryId = $_POST['categoryId'];
$sql = "INSERT INTO Food (FoodID, Name, Price, CategoryID) VALUES (NULL, ?, ?, ?)";
$stmt = $db->prepare($sql);
$stmt->execute([$name, $price, $categoryId]);
}
$result = array();
$result['code'] = '1';
$result['message'] = 'Operation completed successfully.';
echo json_encode($result);