I'm currently doing a project regarding an attendance system using arduino uno and Ethernet shield. For now I have successfully saved the id I get from arduino to the database. My problem is how to make an alert or popup message that says the data has been received and stored in the database every time I receive data from arduino.
Thank you. Below is my arduino code and php code
if (client.connect(myServer, 80)) {
Serial.println("Connecting to Database server");
// send the HTTP PUT request:
client.print("GET /school/inc/jaripelajar.php?P_ID=");
client.print(P_ID);
client.println(" HTTP/1.1");
client.println("Host: 192.168.137.1");
client.println("User-Agent: arduino-ethernet");
client.println("Connection: close");
client.println();
// note the time that the connection was made:
// lastConnectionTime = millis();
while(client.connected()) {
while(client.available()) {
char ch = client.read();
//Serial.write(ch);
}
}
// end of add
client.stop();
}
php code
<script>
$(document).ready(function(e)
{
console.log("html loaded");
});
function redirect(url)
{
window.location = url;
}
<?php
// GET request
foreach ($_REQUEST as $key => $value)
{
if ($key == "P_ID")
{
$P_ID = $value;
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "school";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully
";
//Insert into database
$data1_sql = "INSERT INTO test (P_ID) VALUES ($P_ID)";
$result2 = $conn ->query ($data1_sql);
if(!$result2)
{
die ("The error is: " . mysqli_error($conn));
}
else
{
echo "success";
}
}
}
// Initialize connection to MySQL database
//$device_list = array();
mysqli_close($conn);
?>
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.