-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostdemo.php
More file actions
42 lines (34 loc) · 1.16 KB
/
postdemo.php
File metadata and controls
42 lines (34 loc) · 1.16 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
<?php
//Creates new record as per request
//Connect to database
$servername = "localhost";
$username = "sri_id_4";
$password = "sssa";
$dbname = "espdemo";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Database Connection failed: " . $conn->connect_error);
}
//Get current date and time
date_default_timezone_set('Asia/Kolkata');
$d = date("Y-m-d");
//echo " Date:".$d."<BR>";
$t = date("H:i:s");
if(!empty($_POST['temperature']) && !empty($_POST['humidity']) !empty($_POST['soilmoisture']) && !empty($_POST['rainread']))
{
$temp = $_POST['temperature'];
$hum = $_POST['humidity'];
$soil = $_POST['soilmoisture'];
$rain = $_POST['rainread'];
$sql = "INSERT INTO logs (temperature, humidity, soilmoisture, rainread, Date, Time)
VALUES ('".$temp."', '".$hum."', '".$soil."', '".$rain."', '".$d."', '".$t."')";
if ($conn->query($sql) === TRUE) {
echo "OK";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
$conn->close();
?>