ESP32 Cloud server

To insert data in database

 
<?php
$servername = "localhost";
$username = "iotuser";
$password = "PASS";
$dbname = "iotdata";
// Create connection
$conn = new mysqli($servername, $username,$password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$temp = $_GET['temp'];
$hum = $_GET['hum'];
$sql = "INSERT INTO iottable (temp,hum) VALUES ($temp,'$hum');";
if ($conn->query($sql) === TRUE) {
    echo "the data is saved in database";
} else {
    echo "Error:" . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

To see data on frontend

<html>
<head>
<meta http-equiv="refresh" content="15">
</head> 
<body>
<?php
$servername = "localhost";
$username = "iotuser";
$password = "PASS";
$dbname = "iotdata";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
$sql = "SELECT * FROM iottable";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
	echo "<table border='1'><th>Time</th><th>TEMP</th><th>HUMIDITY</th>";
    while($row = $result->fetch_assoc()) {
		echo "<tr>";
		echo "<td>".$row['time']."</td>";
		echo "<td>".$row['temp']."</td>";
		echo "<td>".$row['hum']."</td>";
 		echo "</tr>";
    }
	echo "</table>";
} else {
    echo "0 results";
}
$conn->close();
?>
</body>
</html>
(0)