getConnection(); // Validazione base if (empty($_POST['id']) || !is_numeric($_POST['id'])) { echo json_encode(['success' => false, 'message' => 'ID non valido.']); exit; } $id = (int)$_POST['id']; $lineNumber = trim($_POST['lineNumber'] ?? ''); $lineName = trim($_POST['lineName'] ?? ''); $model = trim($_POST['model'] ?? ''); $brand = trim($_POST['brand'] ?? ''); $status = trim($_POST['status'] ?? ''); if ($lineNumber === '' || $lineName === '') { echo json_encode(['success' => false, 'message' => 'Numero linea e nome sono obbligatori.']); exit; } // Query UPDATE $sql = "UPDATE production_lines SET line_number = :line_number, name = :name, model = :model, brand = :brand, status = :status WHERE id = :id"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':line_number' => $lineNumber, ':name' => $lineName, ':model' => $model, ':brand' => $brand, ':status' => $status, ':id' => $id ]); echo json_encode(['success' => true]); } catch (Exception $e) { echo json_encode([ 'success' => false, 'message' => 'Errore server: ' . $e->getMessage() ]); }