|  | <?php
$servername = "localhost";
$username = "u488983909_neonflake";
$password = "Tony@1234";
$dbname = "u488983909_neonflake";
$conn = mysqli_connect($servername, $username, $password, $dbname);
$api_key_value = "Neonflake0799";
$api_key = $temperature = $luminosity = $pH= "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $api_key = test_input($_POST["api_key"]);
    if($api_key == $api_key_value) {
        
        $Temp = test_input($_POST["temperature"]);
        $Lumi = test_input($_POST["luminosity"]);
        $ph = test_input($_POST["pH"]);
        
        
        $sql = "INSERT INTO espdata ( Temperature, Luminosity, pH)
        VALUES ('" . $Temp . "', '" . $Lumi . "', '" . $ph . "')";
        
        if ($conn->query($sql) === TRUE) {
            echo "New record created successfully";
        } 
        else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
    
        $conn->close();
    }
    else {
        echo "Wrong API Key provided.";
    }
}
else {
    echo "No data posted with HTTP POST.";
}
function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}
?>
 |