Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deployed Web App - https://cine-scope-ten.vercel.app/
1 change: 1 addition & 0 deletions backend/addComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

$data = json_decode(file_get_contents("php://input"), true);

// get user id, movie id, and comment content
$user_id = $data["user_id"] ?? null;
$movie_id = $data["movie_id"] ?? null;
$content = $data["content"] ?? '';
Expand Down
16 changes: 8 additions & 8 deletions backend/bookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@

require_once "db.php";

// 1. Read raw input
// read input
$rawInput = file_get_contents("php://input");

// DEBUG LOG — write raw input to file for inspection
// debug log
file_put_contents("debug_log.txt", $rawInput . PHP_EOL, FILE_APPEND);

// 2. Decode JSON
// decode JSON
$data = json_decode($rawInput, true);

// 3. Check if valid JSON
// Check if JSON valid
if (!is_array($data)) {
http_response_code(400);
echo json_encode(['error' => 'Invalid JSON input']);
exit;
}

// 4. Extract parameters
// extract user and movie
$user_id = $data['user_id'] ?? null;
$movie_id = $data['movie_id'] ?? null;

Expand All @@ -33,14 +33,14 @@
exit;
}

// 6. Check if already bookmarked
// Check if already bookmarked
$stmt = $conn->prepare("SELECT id FROM lists WHERE user_id = ? AND movie_id = ?");
$stmt->bind_param("ii", $user_id, $movie_id);
$stmt->execute();
$result = $stmt->get_result();

if ($result && $result->num_rows > 0) {
// 7. Already bookmarked remove
// already bookmarked, remove
$delete = $conn->prepare("DELETE FROM lists WHERE user_id = ? AND movie_id = ?");
$delete->bind_param("ii", $user_id, $movie_id);
$success = $delete->execute();
Expand All @@ -51,7 +51,7 @@
]);
$delete->close();
} else {
// 8. Not bookmarked → insert
// not bookmarkedm, insert
$insert = $conn->prepare("INSERT INTO lists (user_id, movie_id) VALUES (?, ?)");
$insert->bind_param("ii", $user_id, $movie_id);
$success = $insert->execute();
Expand Down
7 changes: 4 additions & 3 deletions backend/changePassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

$data = json_decode(file_get_contents("php://input"), true);

// extract data
$user_id = $data['user_id'] ?? '';
$current_password = $data['current_password'] ?? '';
$new_password = $data['new_password'] ?? '';
Expand All @@ -23,20 +24,20 @@
exit;
}

// Get existing hashed password
// get existing hashed password
$stmt = $conn->prepare("SELECT password FROM users WHERE id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();

if ($row = $result->fetch_assoc()) {
// Validate current password
// validate current password
if (!password_verify($current_password, $row['password'])) {
echo json_encode(["error" => "Incorrect current password"]);
exit;
}

// Hash and update new password
// hash and update new password
$new_hashed = password_hash($new_password, PASSWORD_DEFAULT);
$updateStmt = $conn->prepare("UPDATE users SET password = ? WHERE id = ?");
$updateStmt->bind_param("si", $new_hashed, $user_id);
Expand Down
5 changes: 3 additions & 2 deletions backend/checkBookmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");

// Include database connection
require_once "db.php";

// Get user_id and movie_id from GET request
// GET user_id and movie_id
$user_id = $_GET['user_id'] ?? 0;
$movie_id = $_GET['movie_id'] ?? 0;

// by default, bookmarked = false
$response = ['bookmarked' => false];

if ($user_id && $movie_id) {
Expand All @@ -17,6 +17,7 @@
$stmt->execute();
$result = $stmt->get_result();

// if bookmarked, set bookmark as true
if ($result && $result->num_rows > 0) {
$response['bookmarked'] = true;
}
Expand Down
2 changes: 2 additions & 0 deletions backend/getAverageRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
exit;
}

// sql search for the movie
$stmt = $conn->prepare("SELECT AVG(score) AS average, COUNT(*) AS count FROM ratings WHERE movie_id = ?");
$stmt->bind_param("i", $movie_id);
$stmt->execute();
$result = $stmt->get_result();

// count = number of reviews in that movie
if ($row = $result->fetch_assoc()) {
echo json_encode([
"average" => round((float)$row['average'], 1),
Expand Down
4 changes: 4 additions & 0 deletions backend/getBookmarks.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
// get list of bookmarked movies by user

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");

Expand All @@ -11,6 +13,7 @@

$user_id = intval($_GET["user_id"]);

// prepare sql statement, user_id = ?
$sql = "SELECT m.id, m.title, m.genre, m.release_date
FROM lists l
JOIN movies m ON l.movie_id = m.id
Expand All @@ -23,6 +26,7 @@
$result = $stmt->get_result();
$bookmarks = [];

// retrieve bookmarked movies
while ($row = $result->fetch_assoc()) {
$bookmarks[] = $row;
}
Expand Down
1 change: 1 addition & 0 deletions backend/getComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
exit;
}

// select content(comments), and name of user
$sql = "SELECT c.content, u.name
FROM comments c
JOIN users u ON c.user_id = u.id
Expand Down
3 changes: 3 additions & 0 deletions backend/getMovie.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
// going to movie page

error_reporting(E_ALL);
ini_set('display_errors', 1);

Expand All @@ -14,6 +16,7 @@
exit;
}

// select all attributes of movie based on its id
$stmt = $conn->prepare("SELECT * FROM movies WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
Expand Down
3 changes: 3 additions & 0 deletions backend/getMovies.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
// get movies to be shown in the home page

error_reporting(E_ALL);
ini_set('display_errors', 1);

Expand All @@ -12,6 +14,7 @@
exit;
}

// limit to 20 movies ordered by the latest
$sql = "SELECT id, title, genre, release_date FROM movies ORDER BY release_date DESC LIMIT 20";
$result = $conn->query($sql);

Expand Down
1 change: 1 addition & 0 deletions backend/getPreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

$user_id = $_GET['user_id'] ?? 0;

// get user genre preference
$stmt = $conn->prepare("SELECT genre_preference FROM users WHERE id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
Expand Down
2 changes: 2 additions & 0 deletions backend/getRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

require_once "db.php";

// movie and user id as a foreign key of ratings
$user_id = $_GET['user_id'] ?? 0;
$movie_id = $_GET['movie_id'] ?? 0;

Expand All @@ -14,6 +15,7 @@
exit;
}

// get score of a certain movie by the user
$stmt = $conn->prepare("SELECT score FROM ratings WHERE user_id = ? AND movie_id = ?");
$stmt->bind_param("ii", $user_id, $movie_id);
$stmt->execute();
Expand Down
5 changes: 5 additions & 0 deletions backend/getRecommended.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
// 'for you' movie recommendations in home page for logged in users

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");

Expand All @@ -11,12 +13,14 @@
exit;
}

// explode genre array using ','
$genre = explode(',', $genres);

// WHERE clause with genres
$conditions = array_map(fn($g) => "m.genre LIKE ?", $genre);
$whereClause = implode(" OR ", $conditions);

// select movies that have the same genre as the ones in user preference and ordered by average rating
$sql = "
SELECT m.*, ROUND(AVG(r.score), 2) AS average_rating
FROM movies m
Expand All @@ -29,6 +33,7 @@

$stmt = $conn->prepare($sql);

// bind all genres
$types = str_repeat("s", count($genre));
$params = array_map(fn($g) => "%$g%", $genre);
$stmt->bind_param($types, ...$params);
Expand Down
7 changes: 7 additions & 0 deletions backend/getSearch.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
<?php
// search and filtering movie

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");

require_once('db.php');

// GET search parameters
$title = $_GET['title'] ?? '';
$genre = $_GET['genre'] ?? '';
$language = $_GET['language'] ?? '';

// 1=1 as placeholder since its true
$sql = "SELECT id, title, genre, movies.language
FROM movies
WHERE 1=1";
$params = [];
$types = "";

// if user search by title
if (!empty($title)) {
$sql .= " AND title LIKE ?";
$params[] = "%$title%";
$types .= "s";
}

// if user search by genre
if (!empty($genre)) {
$sql .= " AND genre LIKE ?";
$params[] = "%$genre%";
$types .= "s";
}

// if user search by language
if (!empty($language)) {
$sql .= " AND language LIKE ?";
$params[] = "%$language%";
Expand Down
3 changes: 3 additions & 0 deletions backend/getUser.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
// retrieve user credentials for account management page

header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");

Expand All @@ -11,6 +13,7 @@
exit;
}

// retrieve username and email
$stmt = $conn->prepare("SELECT id, name, email FROM users WHERE id = ?");
$stmt->bind_param("i", $user_id);
$stmt->execute();
Expand Down
5 changes: 5 additions & 0 deletions backend/login.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
// login script

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
header("Content-Type: application/json");
Expand All @@ -14,6 +16,7 @@
$email = $data["email"] ?? '';
$password = $data["password"] ?? '';

// if fields are not filled
if (!$email || !$password) {
echo json_encode(["error" => "Missing email or password"]);
exit;
Expand All @@ -24,13 +27,15 @@
$stmt->execute();
$result = $stmt->get_result();

// if email not found
if ($result->num_rows === 0) {
echo json_encode(["error" => "User not found"]);
exit;
}

$user = $result->fetch_assoc();

// check password with stored password using password_verify
if (!password_verify($password, $user["password"])) {
echo json_encode(["error" => "Incorrect password"]);
exit;
Expand Down
4 changes: 3 additions & 1 deletion backend/removeFromList.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php
// remove bookmarked movie from list

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: POST");
header("Content-Type: application/json");

$conn = new mysqli("localhost", "root", "", "cinescope");
require_once "db.php";

$data = json_decode(file_get_contents("php://input"));

Expand Down
2 changes: 2 additions & 0 deletions backend/updatePreference.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
$user_id = $data['user_id'] ?? 0;
$genre = $data['genre_preference'] ?? '';

// prepare statement for incoming genre_preference changes to the user
$stmt = $conn->prepare("UPDATE users SET genre_preference = ? WHERE id = ?");
$stmt->bind_param("si", $genre, $user_id);

// update genre_preference
$success = $stmt->execute();
echo json_encode(["success" => $success]);

Expand Down
Loading