-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit_review.php
More file actions
35 lines (28 loc) · 963 Bytes
/
submit_review.php
File metadata and controls
35 lines (28 loc) · 963 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
32
33
34
35
<?php
session_start();
include "db.php";
include "util.php";
if (!isset($_SESSION["user_id"])) {
die("You must be logged in to submit a review.");
}
$review_id = generateNewUserIdReview($conn);
$user_id = $_SESSION["user_id"];
$instructor_id = $_POST["instructor_id"];
$comment = trim($_POST["comment"]);
$rating = isset($_POST["rating"]) ? intval($_POST["rating"]) : NULL;
// Validattion
if (empty($comment) || empty($instructor_id)) {
die("Missing required data.");
}
// Insert into the reviews table
$sql = "INSERT INTO reviews (review_id , instructor_id, user_id,`rating`, comment) VALUES (?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("sssis", $review_id, $instructor_id, $user_id, $rating, $comment);
$stmt->execute();
if ($stmt->affected_rows > 0) {
echo "success";
header("Location: client_dashboard.php?review=success"); // redirect back to dashboard
exit();
} else {
echo "Failed to submit review.";
}