false, 'message' => '']; try { if ($_SERVER['REQUEST_METHOD'] !== 'POST' || !isset($_POST['iddatadb'])) { throw new Exception('Richiesta non valida'); } $iddatadb = intval($_POST['iddatadb']); $db = DBHandlerSelect::getInstance(); $pdo = $db->getConnection(); // Prepara i dati da aggiornare $updates = []; $values = []; foreach ($_POST as $key => $value) { if ($key !== 'iddatadb') { $updates[] = "$key = ?"; $values[] = htmlspecialchars($value); } } $values[] = $iddatadb; if (empty($updates)) { throw new Exception('Nessun dato da aggiornare'); } $sql = "UPDATE datadb SET " . implode(', ', $updates) . " WHERE iddatadb = ?"; $stmt = $pdo->prepare($sql); $stmt->execute($values); $response['success'] = true; $response['message'] = 'Riga aggiornata con successo'; } catch (Exception $e) { $response['message'] = $e->getMessage(); error_log("Errore in save_edited_row.php: " . $e->getMessage()); } echo json_encode($response); exit;