connect_error) { $response['success'] = false; $response['message'] = 'Verbindung zur Datenbank fehlgeschlagen: ' . $conn->connect_error; echo json_encode($response); // Fehlermeldung als JSON zurückgeben und das Skript beenden exit(); } // SQL-Abfrage mit dem Wert von $notification_days $sql = "INSERT INTO materials (item_name, manufacturer, location, amount_should, amount_is, expiration_date, notification_days, barcode, image, email) VALUES ('$item_name', '$manufacturer', '$location', $amount_should, $amount_is, '$expiration_date', $notification_days, '$barcode', '$image', '$email')"; if ($conn->query($sql) === TRUE) { $response['success'] = true; $response['message'] = 'Neuer Artikel wurde erfolgreich hinzugefügt.'; // Lognachricht zusammenstellen $log_message = date("Y-m-d H:i:s") . " - Artikel hinzugefügt: Artikel: \"$item_name\", Hersteller: \"$manufacturer\", Soll: $amount_should, Ist: $amount_is, MDH: $expiration_date, EAN: \"$barcode\""; // Lognachricht in die Datei schreiben file_put_contents('log.txt', $log_message . PHP_EOL, FILE_APPEND); } else { $response['success'] = false; $response['message'] = 'Fehler beim Hinzufügen des Artikels: ' . $conn->error; } $conn->close(); // JSON-Antwort zurückgeben echo json_encode($response); } ?>