26 lines
723 B
PHP
26 lines
723 B
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Content-Type: application/json');
|
|
echo json_encode(['error' => '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()]);
|
|
}
|
|
?>
|