mysqli.... urgs. Ich war mal so frei und hab es dir hier mal als PDO umgeschrieben mit Error-Handling:
PHP
<?php
try {
// Verbindung zur Datenbank herstellen
$db = new PDO('mysql:host=localhost;dbname=***', '***', '***');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Daten aus Formular sichern
$kid = $_POST['kid'];
$time = $_POST['time'];
$temperatur = $_POST['temperatur'];
$cleaned = $_POST['cleaned'];
$comment = $_POST['comment'];
// Prepared Statement vorbereiten
$query = $db->prepare("INSERT INTO `haccp_temperatur` (`kid`, `time`, `temperatur`, `cleaned`, `comment`) VALUES (:kid, :time, :temperatur, :cleaned, :comment)");
// Parameter binden
$query->bindParam(':kid', $kid, PDO::PARAM_INT);
$query->bindParam(':time', $time, PDO::PARAM_STR);
$query->bindParam(':temperatur', $temperatur, PDO::PARAM_INT);
$query->bindParam(':cleaned', $cleaned, PDO::PARAM_INT);
$query->bindParam(':comment', $comment, PDO::PARAM_STR);
// Prepared Statement ausführen
$query->execute();
// Erfolg ausgeben
echo "Daten erfolgreich gespeichert!";
} catch (PDOException $e) {
// Fehler behandeln
echo "Fehler beim Speichern der Daten: " . $e->getMessage();
}
?>
Alles anzeigen