-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp32postRequest.php
36 lines (25 loc) · 1.31 KB
/
esp32postRequest.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
<?php
//what to do if in the post array I receive the variables temp and tempF
if(isset($_POST["temp"])&&isset($_POST["tempF"])) {
$tempC = $_POST['temp'];
$tempF = $_POST['tempF'];
$servername = "sql.yourWebsite.com"; //your hosting provider will give you this
$username = $db = "USERNAME TO LOG IN THE DATABASE"; //your hosting provider will give you this, in my case it is the same as database name
$password = "mere28190"; //your hosting provider will give you this when you create the database
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
//this is the MySQL query that inserts in the table sensor_reading the following data, you must have created the table and the columns of the database through your php MyAdmin
$sql = 'INSERT INTO `sensor_reading`(`user`, `temperatureC`, `temperatureF`, `date`, `hour`) VALUES ("Peter","'.$tempF.'","'.$tempC.'",now(),now())';
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>