|
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "datasensor";
-
-
- $conn = mysqli_connect($servername, $username, $password, $dbname);
-
- $api_key_value = "ideogen";
-
- $api_key = $Tank1 = $Tank2 = $rainwater = $Turbidity = $pH_sensor= "";
-
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- $api_key = test_input($_POST["api_key"]);
- if($api_key == $api_key_value) {
-
- $Tank1 = test_input($_POST["Tank1"]);
- $Tank2 = test_input($_POST["Tank2"]);
- $rainwater = test_input($_POST["rainwater"]);
- $Turbidity = test_input($_POST["Turbidity"]);
- $pH_sensor = test_input($_POST["pH_sensor"]);
-
-
- $sql = "INSERT INTO sensordata ( Tank1, Tank2, rainwater, Turbidity,pH_sensor)
- VALUES ('" . $Tank1 . "', '" . $Tank2 . "', '" . $rainwater . "', '" . $Turbidity . "', '" . $pH_sensor . "')";
-
- 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;
- }
- ?>
|