-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit_ratings.php
More file actions
51 lines (43 loc) · 1.38 KB
/
submit_ratings.php
File metadata and controls
51 lines (43 loc) · 1.38 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
session_start();
include 'site_database.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$prof_id = intval($_POST['prof_id']);
if (!isset($_SESSION['student_id'])) {
die("You must be logged in to rate a professor.");
}
$student_id = $_SESSION['student_id'];
if ($prof_id <= 0) {
die("Invalid professor ID.");
}
$ratings = [
$_POST['teachingStyle'],
$_POST['answeringQuestions'],
$_POST['workload'],
$_POST['examBasedOn'],
$_POST['approachability'],
$_POST['respect'],
$_POST['assignments'],
$_POST['feedback'],
$_POST['classTimeliness'],
$_POST['academicGrowth'],
$_POST['recommendation']
];
$avg_rating = round(array_sum($ratings) / count($ratings), 2);
$rounded_rating = round($avg_rating);
$query = "
INSERT INTO prof_avg_ratings (prof_id, student_id, avg_rating, rounded_rating)
VALUES ($prof_id, $student_id, $avg_rating, $rounded_rating)
ON DUPLICATE KEY UPDATE
avg_rating = $avg_rating,
rounded_rating = $rounded_rating,
updated_at = CURRENT_TIMESTAMP;
";
if (mysqli_query($conn, $query)) {
echo "Thank you for your feedback!";
} else {
echo "Error: " . mysqli_error($conn);
}
mysqli_close($conn);
}
?>