You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

post-esp-data.php 1.3 KiB

пре 2 година
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. $servername = "localhost";
  3. $username = "root";
  4. $password = "";
  5. $dbname = "datasensor";
  6. $conn = mysqli_connect($servername, $username, $password, $dbname);
  7. $api_key_value = "ideogen";
  8. $api_key = $Tank1 = $Tank2 = $rainwater = $Turbidity = $pH_sensor= "";
  9. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  10. $api_key = test_input($_POST["api_key"]);
  11. if($api_key == $api_key_value) {
  12. $Tank1 = test_input($_POST["Tank1"]);
  13. $Tank2 = test_input($_POST["Tank2"]);
  14. $rainwater = test_input($_POST["rainwater"]);
  15. $Turbidity = test_input($_POST["Turbidity"]);
  16. $pH_sensor = test_input($_POST["pH_sensor"]);
  17. $sql = "INSERT INTO sensordata ( Tank1, Tank2, rainwater, Turbidity,pH_sensor)
  18. VALUES ('" . $Tank1 . "', '" . $Tank2 . "', '" . $rainwater . "', '" . $Turbidity . "', '" . $pH_sensor . "')";
  19. if ($conn->query($sql) === TRUE) {
  20. echo "New record created successfully";
  21. }
  22. else {
  23. echo "Error: " . $sql . "<br>" . $conn->error;
  24. }
  25. $conn->close();
  26. }
  27. else {
  28. echo "Wrong API Key provided.";
  29. }
  30. }
  31. else {
  32. echo "No data posted with HTTP POST.";
  33. }
  34. function test_input($data) {
  35. $data = trim($data);
  36. $data = stripslashes($data);
  37. $data = htmlspecialchars($data);
  38. return $data;
  39. }
  40. ?>