-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddItem.php
40 lines (25 loc) · 1.08 KB
/
addItem.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
36
37
38
39
40
<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, X-Token-Auth, Authorization");
require_once "config/db.php";
$db = new DatabaseConnection();
$conn = $db->getConnection();
$data = json_decode(file_get_contents("php://input"));
$req = $data;
//Sanitize Inputs
$name = filter_var($req->name, FILTER_SANITIZE_STRING);
$type = filter_var($req->type, FILTER_SANITIZE_STRING);
$price = filter_var($req->price, FILTER_SANITIZE_STRING);
$desc = filter_var($req->description, FILTER_SANITIZE_STRING);
$img = filter_var($req->itemPic, FILTER_SANITIZE_STRING);
$query = "INSERT INTO `food` (`id`, `name`, `type`, `price`, `description`, `image`) VALUES (NULL, '$name', '$type', $price, '$desc','$img');";
echo $query;
if($conn->query($query)){
http_response_code(200);
echo json_encode("successfuly added item");
} else{
http_response_code(200);
echo json_encode("error");
}
?>