getConnection(); $userId = (int)($iduserlogin ?? 0); if ($userId <= 0) { header("Location: login.php"); exit; } // Ogni preferenza: colonna DB => 1 se checkbox spuntata, 0 altrimenti $prefsMap = [ 'notify_export_email' => isset($_POST['notify_export_email']) ? 1 : 0, // in futuro: 'notify_altra_cosa' => isset($_POST['notify_altra_cosa']) ? 1 : 0, ]; try { $sets = []; $params = []; foreach ($prefsMap as $col => $val) { $sets[] = "`{$col}` = :{$col}"; $params[$col] = $val; } $params['id'] = $userId; $sql = "UPDATE auth_users SET " . implode(', ', $sets) . " WHERE id = :id"; $stmt = $pdo->prepare($sql); $stmt->execute($params); header("Location: notification_settings.php?saved=1"); exit; } catch (Exception $e) { error_log("Notification prefs update error: " . $e->getMessage()); header("Location: notification_settings.php?saved=0"); exit; }