-
Notifications
You must be signed in to change notification settings - Fork 0
/
getiteminfo.php
49 lines (41 loc) · 1.15 KB
/
getiteminfo.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
<?php
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
if (!isset($_SERVER["HTTP_HOST"])) {
parse_str($argv[1], $_GET);
parse_str($argv[1], $_POST);
}
include('db.php');
header("Content-Type: application/json");
$barcode = trim($_GET['barcode']);
if (!is_numeric($barcode))
{
$pg1 = array('error' => 'invalid request');
}
else
{
try {
$db = new PDO($db_pdostr, $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$lQuery = "SELECT * FROM foodstop_items WHERE barcode like '%" . $barcode . "' ";
error_log( "Query --> " . $lQuery );
$stmt = $db->prepare($lQuery);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if ($row != null)
{
$pg1 = array('barcode' => $row['barcode'], 'id' => $row['id'], 'price' => $row['price'], 'desc' => $row['desc'], 'createdate' => $row['createdate'], 'updatedate' => $row['updatedate'], 'stock' => $row['stock']);
}
else
{
$pg1 = array('error' => 'unknown item');
}
}
catch (PDOException $ex)
{
$pg1 = array('error' => 'database error: '.$ex->getFile().':'.$ex->getLine().' -> '.$ex->getMessage());
}
}
echo json_encode($pg1);
exit();
?>