-
Notifications
You must be signed in to change notification settings - Fork 1
/
post-data.php
80 lines (74 loc) · 2.79 KB
/
post-data.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/*
Copyright 2021 Stuart A Spray - 'simplyEnginering'
With elements by Rui Santos https://RandomNerdTutorials.co
*/
$servername = "localhost";
// REPLACE with your Database name
$dbname = "*********";
// REPLACE with Database user
$username = "*************";
// REPLACE with Database user password
$password = "***************";
$api_key_value = "********************";
$err= "";
$err1= "";
$api_key = $temperature= $pressure= $humidity= $light= $weight= $battery= $sequence= $rxreset= $packet= $postcount= $rssi= $lostpackets= $quality= $CO2= $VOC="";
$api_key = test_input($_POST["api_key"]);
if($api_key == $api_key_value)
{
$temperature = test_input($_POST["temperature"]);
$pressure= test_input($_POST["pressure"]);
$humidity= test_input($_POST["humidity"]);
$light= test_input($_POST["light"]);
$weight= test_input($_POST["weight"]);
$battery= test_input($_POST["battery"]);
$sequence= test_input($_POST["sequence"]);
$rxreset= test_input($_POST["rxreset"]);
$packet= test_input($_POST["packet"]);
$postcount= test_input($_POST["postcount"]);
$rssi= test_input($_POST["rssi"]);
$lostpackets= test_input($_POST["lostpackets"]);
$quality= test_input($_POST["quality"]);
$CO2= test_input($_POST["CO2"]);
$VOC= test_input($_POST["VOC"]);
// Create connection
// Check connection
echo "Hi";
$conn = mysqli_connect($servername,$username,$password,$dbname);
if ($conn->connect_error)
{
$err= "Connect failure";
die("Connection failed: " . $conn->connect_error);
}
else $err= "Connect success";
$sql = "INSERT INTO LoRaLog(temperature, pressure, humidity,light,weight,battery,sequence,rxreset,packet,postcount,rssi,lostpackets,quality,CO2,VOC)
VALUES ('" . $temperature. "', '" . $pressure. "', '" . $humidity. "','" . $light. "', '" . $weight. "', '" . $battery. "','" . $sequence. "','" . $rxreset. "','" . $packet. "','" . $postcount. "','" . $rssi. "','" . $lostpackets. "','" . $quality."','" . $CO2."','" . $VOC."')";
echo $sql;
echo $err;
if ($conn->query($sql) === TRUE)
{
$err1 = "record added";
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "<br>" . $conn->error;
$err1 = "record NOT added";
}
$conn->close();
echo "err1";
}
else
{
echo $sql;
echo "Wrong API Key provided.";
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>