-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_reaction_score.php
34 lines (27 loc) · 1.02 KB
/
get_reaction_score.php
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
<?php
session_start();
// Include database connection
include('database.php');
// Check if the user is logged in using the correct session variable
if (!isset($_SESSION['username'])) {
// If not logged in, return an error response
echo json_encode(array('success' => false, 'message' => 'User not logged in'));
exit();
}
$username = $_SESSION['username'];
// Prepare and execute the SQL query to retrieve the reaction test score
$query = "SELECT score FROM reaction_test_scores WHERE username = ?";
$stmt = $conn->prepare($query);
$stmt->bind_param('s', $username);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$score = $row['score'] !== null ? $row['score'] : null; // Current reaction test score, default to null if null
echo json_encode(array('success' => true, 'reactionScore' => $score)); // Return reaction test score
} else {
echo json_encode(array('success' => false, 'message' => 'User not found'));
}
$stmt->close();
$conn->close();
?>