Thu, 16 Aug 2018 16:01:13 +0200
Better error messages in syslog
12 | 1 | <?php |
2 | ||
3 | require($_SERVER['DOCUMENT_ROOT']."/config.php"); | |
4 | require($_SERVER['DOCUMENT_ROOT']."/version.php"); | |
5 | ||
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
6 | syslog(LOG_NOTICE, "db_inventory_hops: script start"); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
7 | |
12 | 8 | #Connect to the database |
9 | $connect = mysqli_connect(DBASE_HOST, DBASE_USER, DBASE_PASS, DBASE_NAME); | |
10 | if (! $connect) { | |
11 | die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); | |
12 | } | |
13 | ||
14 | // get data and store in a json array | |
15 | $query = "SELECT * FROM inventory_hops"; | |
16 | if (isset($_GET['insert'])) { | |
17 | // INSERT COMMAND | |
18 | $sql = "INSERT INTO `inventory_hops` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); | |
19 | $sql .= "', alpha='" . $_GET['alpha']; | |
20 | $sql .= "', beta='" . $_GET['beta']; | |
21 | $sql .= "', humulene='" . $_GET['humulene']; | |
22 | $sql .= "', caryophyllene='" . $_GET['caryophyllene']; | |
23 | $sql .= "', cohumulone='" . $_GET['cohumulone']; | |
24 | $sql .= "', myrcene='" . $_GET['myrcene']; | |
13 | 25 | $sql .= "', hsi='" . $_GET['hsi']; |
12 | 26 | $sql .= "', useat='" . $_GET['useat']; |
27 | $sql .= "', type='" . $_GET['type']; | |
28 | $sql .= "', form='" . $_GET['form']; | |
29 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); | |
30 | $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']); | |
31 | $sql .= "', substitutes='" . mysqli_real_escape_string($connect, $_GET['substitutes']); | |
32 | ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; | |
33 | $sql .= "', inventory='" . $_GET['inventory']; | |
34 | $sql .= "', cost='" . $_GET['cost']; | |
35 | $sql .= "', production_date='" . $_GET['production_date']; | |
36 | $sql .= "', tht_date='" . $_GET['tht_date']; | |
37 | $sql .= "', supplier_rec='" . $_GET['supplier_rec']; | |
13 | 38 | $sql .= "', total_oil'" . $_GET['total_oil']; |
12 | 39 | $sql .= "';"; |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
40 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
41 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
42 | syslog(LOG_NOTICE, "db_inventory_hops: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
43 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
44 | syslog(LOG_NOTICE, "db_inventory_hops: inserted ".$_GET['name']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
45 | } |
12 | 46 | echo $result; |
47 | ||
48 | } else if (isset($_GET['update'])) { | |
49 | // UPDATE COMMAND | |
50 | $sql = "UPDATE `inventory_hops` SET name='" . mysqli_real_escape_string($connect, $_GET['name']); | |
51 | $sql .= "', alpha='" . $_GET['alpha']; | |
52 | $sql .= "', beta='" . $_GET['beta']; | |
53 | $sql .= "', humulene='" . $_GET['humulene']; | |
54 | $sql .= "', caryophyllene='" . $_GET['caryophyllene']; | |
55 | $sql .= "', cohumulone='" . $_GET['cohumulone']; | |
56 | $sql .= "', myrcene='" . $_GET['myrcene']; | |
13 | 57 | $sql .= "', hsi='" . $_GET['hsi']; |
12 | 58 | $sql .= "', useat='" . $_GET['useat']; |
59 | $sql .= "', type='" . $_GET['type']; | |
60 | $sql .= "', form='" . $_GET['form']; | |
61 | $sql .= "', notes='" . mysqli_real_escape_string($connect, $_GET['notes']); | |
62 | $sql .= "', origin='" . mysqli_real_escape_string($connect, $_GET['origin']); | |
63 | $sql .= "', substitutes='" . mysqli_real_escape_string($connect, $_GET['substitutes']); | |
64 | ($_GET['always_on_stock'] == 'true') ? $sql .= "', always_on_stock='1" : $sql .= "', always_on_stock='0"; | |
65 | $sql .= "', inventory='" . $_GET['inventory']; | |
66 | $sql .= "', cost='" . $_GET['cost']; | |
67 | $sql .= "', production_date='" . $_GET['production_date']; | |
68 | $sql .= "', tht_date='" . $_GET['tht_date']; | |
69 | $sql .= "', supplier_rec='" . $_GET['supplier_rec']; | |
13 | 70 | $sql .= "', total_oil'" . $_GET['total_oil']; |
12 | 71 | $sql .= "' WHERE record='" . $_GET['record'] . "';"; |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
72 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
73 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
74 | syslog(LOG_NOTICE, "db_inventory_hops: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
75 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
76 | syslog(LOG_NOTICE, "db_inventory_hops: updated record ".$_GET['record']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
77 | } |
12 | 78 | echo $result; |
79 | ||
80 | } else if (isset($_GET['delete'])) { | |
81 | // DELETE COMMAND | |
82 | $sql = "DELETE FROM `inventory_hops` WHERE record='".$_GET['record']."';"; | |
18
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
83 | $result = mysqli_query($connect, $sql); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
84 | if (! $result) { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
85 | syslog(LOG_NOTICE, "db_inventory_hops: ".$sql." result: ".mysqli_error($connect)); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
86 | } else { |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
87 | syslog(LOG_NOTICE, "db_inventory_hops: deleted record ".$_GET['record']); |
395833e20f88
Better error messages in syslog
Michiel Broek <mbroek@mbse.eu>
parents:
13
diff
changeset
|
88 | } |
12 | 89 | echo $result; |
90 | ||
91 | } else { | |
92 | // SELECT COMMAND | |
93 | $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); | |
94 | while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { | |
95 | $hops[] = array( | |
96 | 'record' => $row['record'], | |
97 | 'name' => $row['name'], | |
98 | 'alpha' => $row['alpha'], | |
99 | 'beta' => $row['beta'], | |
100 | 'humulene' => $row['humulene'], | |
101 | 'caryophyllene' => $row['caryophyllene'], | |
102 | 'cohumulone' => $row['cohumulone'], | |
103 | 'myrcene' => $row['myrcene'], | |
13 | 104 | 'hsi' => $row['hsi'], |
12 | 105 | 'useat' => $row['useat'], |
106 | 'type' => $row['type'], | |
107 | 'form' => $row['form'], | |
108 | 'notes' => $row['notes'], | |
109 | 'origin' => $row['origin'], | |
110 | 'substitutes' => $row['substitutes'], | |
111 | 'always_on_stock' => $row['always_on_stock'], | |
112 | 'inventory' => $row['inventory'], | |
113 | 'cost' => $row['cost'], | |
114 | 'production_date' => $row['production_date'], | |
115 | 'tht_date' => $row['tht_date'], | |
13 | 116 | 'supplier_rec' => $row['supplier_rec'], |
117 | 'total_oil' => $row['total_oil'] | |
12 | 118 | ); |
119 | } | |
120 | echo json_encode($hops); | |
121 | } | |
122 | ?> |