commit beda041affacdf47db41929a4ccf2d846dcc9ddc
parent f7841fe7ec243eb65d4c96f460b219d738535106
Author: Kninteman <[email protected]>
Date: Sat, 25 Mar 2023 16:16:23 +0100
Update datainserter.php
Diffstat:
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/datainserter.php b/datainserter.php
@@ -1,4 +1,5 @@
<?php
+// Server connection details
$servername = "86.92.67.21";
$username = "friedel";
$password = "hailiwa";
@@ -13,11 +14,13 @@ if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
-
+// Check if request method is POST
if ($_SERVER["REQUEST_METHOD"] == "POST") {
+
+ // Include datavalidator
include 'datavalidator.php';
- // collect value of input field
+ // Collect value of input fields
$station = $_POST['STN'];
$date = $_POST['DATE'];
$time = $_POST['TIME'];
@@ -39,11 +42,15 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Prepare SQL INSERT-statement
$sql = "INSERT INTO weerdata VALUES (?, DATE_FORMAT(?, '%Y%m%d%H%i'), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
- // Bind parameters
+ // Create prepared statement with the SQL statement
$stmt = mysqli_prepare($conn, $sql);
+
+ // Concatenate date and time
$datetime = $date . $time;
+
+ // Bind parameters to prepared statement
mysqli_stmt_bind_param($stmt, "ssi", $station, $datetime, $valid, $dauwpunt, $luchtdrukzeeniveau, $luchtdrukstationniveau, $zichtbaarheid, $windsnelheid, $neerslag, $sneeuwdiepte, $gebeurtenissen, $bewolking, $windrichting);
- // Execute statement
+ // Execute prepared statement
$result = mysqli_stmt_execute($stmt);
}