connect_error) { die("Connection failed: " . $conn->connect_error); } // Controlla se il JSON è stato ricevuto tramite POST if ($_SERVER['REQUEST_METHOD'] === 'POST') { // Riceve il JSON dal laboratorio $json_data = file_get_contents('php://input'); // Decodifica il JSON per la validazione (facoltativa) $decoded_data = json_decode($json_data, true); // Se il JSON è valido if (json_last_error() === JSON_ERROR_NONE) { // Genera un UUID per identificare univocamente il record $uuid = uniqid(); // Alternativamente puoi usare UUID() in MySQL // ID del laboratorio dal quale proviene il JSON (puoi aggiungere autenticazione) $lab_id = isset($_POST['lab_id']) ? $_POST['lab_id'] : 'Unknown Lab'; // Modifica a seconda della tua logica // Estrai alcune informazioni dal JSON $product_refnumber = $decoded_data['product']['products_refnumber']; // Numero prodotto $report_number = $decoded_data['product']['reports'][0]['reportsNumberLab']; // Numero report $saved_at = date("Y-m-d H:i:s"); // Data del salvataggio // Query per inserire i dati nella tabella temp_json_queue $stmt = $conn->prepare("INSERT INTO temp_json_queue (uuid, lab_id, json_data) VALUES (?, ?, ?)"); $stmt->bind_param("sss", $uuid, $lab_id, $json_data); if ($stmt->execute()) { echo json_encode([ "status" => "success", "message" => "Data successfully saved.", "uuid" => $uuid, "product_refnumber" => $product_refnumber, // Numero del prodotto "report_number" => $report_number, // Numero del report "saved_at" => $saved_at // Data del salvataggio ]); } else { echo json_encode([ "status" => "error", "message" => "Failed to save data." ]); } $stmt->close(); } else { // Se il JSON è invalido echo json_encode([ "status" => "error", "message" => "Invalid JSON format." ]); } } else { echo json_encode([ "status" => "error", "message" => "Invalid request method." ]); } // Chiude la connessione al database $conn->close();