-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRate.php
More file actions
30 lines (27 loc) · 1.03 KB
/
Copy pathRate.php
File metadata and controls
30 lines (27 loc) · 1.03 KB
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
<?php
session_start();
include 'db_connect.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['id'], $_SESSION['username'], $_POST['rating'])) {
$title_id = $_POST['id'];
$username = $_SESSION['username'];
$rating = $_POST['rating'];
try {
$sql = "INSERT INTO userRating (titleid, username, rating) VALUES (:id, :username, :rating)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':id', $title_id, PDO::PARAM_STR);
$stmt->bindParam(':username', $username, PDO::PARAM_STR);
$stmt->bindParam(':rating', $rating, PDO::PARAM_INT);
$stmt->execute();
if ($stmt->rowCount() > 0) {
header("Location: " . $_SERVER['HTTP_REFERER'] . "&errorRat=Rating Added");
exit();
}
} catch (PDOException $e) {
header("Location: " . $_SERVER['HTTP_REFERER'] . "&errorRa=Already Rated");
exit();
}
}
} else {
echo "Invalid request method.";
}