-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsence.php
More file actions
55 lines (38 loc) · 1.65 KB
/
sence.php
File metadata and controls
55 lines (38 loc) · 1.65 KB
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
<?php
$order = $_GET['order'];
if (isset($_GET['data1']))
$data1 = $_GET['data1'];
if (isset($_GET['data2']))
$data2= $_GET['data2'];
if (isset($_GET['data3']))
$data3 = $_GET['data3'];
$servername = "127.0.0.1";
$DBusername = "root";
$password = "";
$dbname = "smarthouse";
$conn = new mysqli($servername, $DBusername, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "SElECT type_code from sell as s , product_stock as p where s.product_code = p.product_code and s.order_number = " . $order . ";";
$result = $conn->query($query);
while ($row = $result->fetch_assoc()) {
if ($result->num_rows > 0) {
if ($row["type_code"] == 1) {
$sql = "INSERT INTO light_sensor (order_number, report_time,light_intensity, base_light_intensity)
VALUES ('" . $order . "', CURRENT_TIME, '" . $data2 . "', '" . $data2 . "')" ;
echo $sql;
} else if ($row["type_code"] == 2) {
$sql = "INSERT INTO temperature_sensor (order_number, report_time,temperature)
VALUES ('" . $order . "', CURRENT_TIME, '" . $data1 . "')" ;
} else if ($row["type_code"] == 3) {
$sql = "INSERT INTO humidity_sensor (order_number, report_time,humidity)
VALUES ('" . $order . "', CURRENT_TIME, '" . $data1 . "')" ;
} else if ($row["type_code"] == 4) {
$sql = "INSERT INTO gas_Sensor (order_number, report_time,co2, co,ch4)
VALUES ('" . $order . "', CURRENT_TIME, '" . $data2 . "', '" . $data2 . "', '" . $data3 . "')" ;
}
if ($conn->query($sql) === TRUE) {
}
}
}