-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset_reaction_score.php
42 lines (35 loc) · 1.08 KB
/
reset_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
35
36
37
38
39
40
41
42
<?php
session_start();
include('database.php');
// Check if admin is logged in
if (!isset($_SESSION['admin_id'])) {
// Redirect or show an error if not an admin
header("Location: signin.php");
exit();
}
// Check if username parameter is provided
if (!isset($_GET['username'])) {
// Redirect or show an error if username is missing
header("Location: " . $_SERVER['HTTP_REFERER'] . "?error=missing_username");
exit();
}
// Get the username to reset
$usernameToReset = filter_var($_GET['username'], FILTER_SANITIZE_STRING);
// Prepare and execute the update query
$updateQuery = "UPDATE reaction_test_scores SET score = null WHERE username = ?";
$stmt = $conn->prepare($updateQuery);
$stmt->bind_param("s", $usernameToReset);
if ($stmt->execute()) {
// User deleted successfully
header("Location: " . $_SERVER['PHP_SELF']);
exit();
} else {
// Rollback the transaction if an error occurred
$conn->rollback();
// Error occurred while deleting the user
header("Location: " . $_SERVER['PHP_SELF']);
exit();
}
$stmt->close();
$conn->close();
?>