31 lines
785 B
PHP
31 lines
785 B
PHP
<?php
|
|
require_once __DIR__ . '/../db/config.php';
|
|
|
|
session_start();
|
|
header('Content-Type: application/json');
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
http_response_code(401);
|
|
echo json_encode(['status' => 'error', 'message' => 'You must be logged in to view favorites.']);
|
|
exit;
|
|
}
|
|
|
|
$userId = $_SESSION['user_id'];
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
$stmt = $pdo->prepare(
|
|
'SELECT p.* FROM players p JOIN user_favorites uf ON p.id = uf.player_id WHERE uf.user_id = ?'
|
|
);
|
|
$stmt->execute([$userId]);
|
|
|
|
$favorites = $stmt->fetchAll();
|
|
|
|
echo json_encode(['status' => 'success', 'favorites' => $favorites]);
|
|
|
|
} catch (PDOException $e) {
|
|
http_response_code(500);
|
|
echo json_encode(['status' => 'error', 'message' => 'Database error: ' . $e->getMessage()]);
|
|
}
|