-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetFavoriteMovies.php
More file actions
31 lines (24 loc) · 930 Bytes
/
getFavoriteMovies.php
File metadata and controls
31 lines (24 loc) · 930 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
header('Content-Type: application/json');
require_once 'conexao.php'; // Arquivo que contém a conexão com o banco de dados
session_start(); // Inicia a sessão
if (isset($_SESSION["userid"])) {
$userId = $_SESSION["userid"]; // ID do usuário autenticado
$stmt = $conn->prepare("SELECT movie_id, title, genres, poster_path FROM favorites WHERE user_id = ?");
$stmt->bind_param("i", $userId);
if ($stmt->execute()) {
$result = $stmt->get_result();
$favorites = [];
while ($row = $result->fetch_assoc()) {
$favorites[] = $row;
}
echo json_encode($favorites);
} else {
echo json_encode(['success' => false, 'message' => 'Erro ao recuperar filmes favoritos.']);
}
$stmt->close();
$conn->close();
} else {
echo json_encode(['success' => false, 'message' => 'Usuário não está logado.']);
}
?>