-
Notifications
You must be signed in to change notification settings - Fork 1
/
items.php
54 lines (44 loc) · 1.07 KB
/
items.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
include_once("dbconnect.php");
include_once("response.php");
if(!empty($_POST))
{
$name = $_POST["name"];
$price = $_POST["price"];
$userID = $_POST["user_id"];
addItem($name, $price, "", $user_id, "");
}
if(!empty($_GET))
{
$id = $_GET["item_id"];
getItem($id);
}
function getItem($itemID)
{
$conn = connect();
$sql = "SELECT * FROM item WHERE item_id = $itemID";
$stmt = $conn->query($sql);
sendResponse(200, json_encode($stmt->fetchAll(PDO::FETCH_ASSOC)));
}
function getAllItems()
{
$conn = connect();
$sql = "SELECT * FROM item";
$stmt = $conn->query($sql);
sendResponse(200, json_encode($stmt->fetchAll(PDO::FETCH_ASSOC)));
}
function addItem($name, $price, $description, $user_id, $image_url)
{
$conn = connect();
$sql = "INSERT INTO item (name, price, description, user_id, image) VALUES (?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bindValue(1, $name);
$stmt->bindValue(2, $price);
$stmt->bindValue(3, $description);
$stmt->bindValue(4, $user_id);
$stmt->bindValue(5, $image_url);
$stmt->execute();
}
//getItem(2);
getAllItems();
?>