iwa-panda1

Manage Weather Data by International Weather Agency (Version 1)
Log | Files | Refs

commit f7841fe7ec243eb65d4c96f460b219d738535106
parent af3d62cf07aaf94ad30ec7a3f69c35fdc8e8344f
Author: Kninteman <[email protected]>
Date:   Sat, 25 Mar 2023 16:13:36 +0100

Update datainserter.php

Diffstat:
Mdatainserter.php | 19+++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/datainserter.php b/datainserter.php @@ -7,6 +7,7 @@ $dbname = "wap2"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); + // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); @@ -15,6 +16,7 @@ if (!$conn) { if ($_SERVER["REQUEST_METHOD"] == "POST") { include 'datavalidator.php'; + // collect value of input field $station = $_POST['STN']; $date = $_POST['DATE']; @@ -31,12 +33,17 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") { $bewolking = $_POST['CLDC']; $windrichting = $_POST['WNDDIR']; + // Validate temperature $valid = validate_temperature($station, $temperatuur, $conn); - if ($valid) { - $sql = "Insert into weerdata Values($station, conc($date, $time), 1, $gebeurtenissen, $temperatuur, $dauwpunt, $luchtdrukzeeniveau, $luchtdrukstationniveau, $zichtbaarheid, $windsnelheid, $neerslag, $sneeuwdiepte, $gebeurtenissen, $bewolking, $windrichting,)"; - } else { - $sql = "Insert into weerdata Values($station, conc($date, $time), 0, $gebeurtenissen, $temperatuur, $dauwpunt, $luchtdrukzeeniveau, $luchtdrukstationniveau, $zichtbaarheid, $windsnelheid, $neerslag, $sneeuwdiepte, $gebeurtenissen, $bewolking, $windrichting,)"; - } - $result = mysqli_query($conn, $sql); + // Prepare SQL INSERT-statement + $sql = "INSERT INTO weerdata VALUES (?, DATE_FORMAT(?, '%Y%m%d%H%i'), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + + // Bind parameters + $stmt = mysqli_prepare($conn, $sql); + $datetime = $date . $time; + mysqli_stmt_bind_param($stmt, "ssi", $station, $datetime, $valid, $dauwpunt, $luchtdrukzeeniveau, $luchtdrukstationniveau, $zichtbaarheid, $windsnelheid, $neerslag, $sneeuwdiepte, $gebeurtenissen, $bewolking, $windrichting); + + // Execute statement + $result = mysqli_stmt_execute($stmt); }