'User not logged in']); exit(); } $user_id = $_SESSION['user_id']; try { $pdo = db(); $stmt = $pdo->prepare("SELECT id, city, lat, lon FROM favorite_locations WHERE user_id = ? ORDER BY city"); $stmt->execute([$user_id]); $locations = $stmt->fetchAll(PDO::FETCH_ASSOC); header('Content-Type: application/json'); echo json_encode($locations); } catch (PDOException $e) { header('Content-Type: application/json'); http_response_code(500); echo json_encode(['error' => 'Database error: ' . $e->getMessage()]); } ?>