-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_user_type.php
56 lines (46 loc) · 1.72 KB
/
update_user_type.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
// update_user_type.php
// update_user_type.php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Check if the member ID and user type are provided
if (isset($_POST['memberId']) && isset($_POST['userType'])) {
$memberId = $_POST['memberId'];
$userType = $_POST['userType'];
// Map the user type string to corresponding values
$userTypeValues = [
'admin' => 1,
'user' => 2,
'suspended' => 3
];
// Check if the user type exists in the mapping array
if (isset($userTypeValues[$userType])) {
$userTypeValue = $userTypeValues[$userType];
// Update the user type in the database
$conn = mysqli_connect("localhost", "root", "", "local_theatre2");
if (!$conn) {
die(mysqli_connect_error());
}
// Prepare the query with a parameter
$query = "UPDATE member SET utype = ? WHERE member_id = ?";
$stmt = mysqli_prepare($conn, $query);
// Bind the parameter values
mysqli_stmt_bind_param($stmt, "ii", $userTypeValue, $memberId);
// Execute the prepared statement
$result = mysqli_stmt_execute($stmt);
if ($result) {
echo "User type updated successfully.";
} else {
echo "Failed to update user type.";
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
} else {
echo "Invalid user type.";
}
} else {
echo "Invalid request. Member ID and user type are required.";
}
} else {
echo "Invalid request method.";
}
?>