-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_modify_user.php
60 lines (48 loc) · 2.02 KB
/
admin_modify_user.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
57
58
59
60
<?php
header("Content-Type: application/json; charset=utf-8");
session_start();
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$_userid = $_POST["userId"];
$_username = $_POST["modify_username"];
$_password = $_POST["modify_password"];
$_role = $_POST["modify_role"];
$_member = $_POST["modify_member"];
echo("<script>console.log('".json_encode($_userid)."');</script>");
echo("<script>console.log('".json_encode($_username)."');</script>");
echo("<script>console.log('".json_encode($_password)."');</script>");
echo("<script>console.log('".json_encode($_role)."');</script>");
echo("<script>console.log('".json_encode($_member)."');</script>");
// if($_role == '1')
// $_role = "admin";
// else if($_role == '2')
// $_role = "member";
// echo("<script>console.log('".json_encode($_role)."');</script>");
// 连接到数据库
// $conn = mysqli_connect("localhost", "root", "root", "snack");
$conn = mysqli_connect("localhost", "root", "root1234", "snack");
if (!$conn)
die("数据库连接失败: " . mysqli_connect_error());
$snackid = null;
$query = "SELECT * FROM users WHERE user_id = ?";
$stmt0 = $conn->prepare($query);
$stmt0->bind_param("i", $_userid);
$stmt0->execute();
$stmt0->store_result();
if (!$stmt0->fetch()) {
$stmt0->close();
echo json_encode(["success" => false, "message" => "用户不存在" . $stmt->error]);
} else {
$stmt0->close();
$update_query = "UPDATE users SET username = ?, password = ?, role = ?, member = ? WHERE user_id = ?";
$stmt = $conn->prepare($update_query);
$stmt->bind_param("sssii", $_username, $_password, $_role, $_member, $_userid);
if ($stmt->execute()) {
echo json_encode(["success" => true, "message" => "The snack was successfully to modify user."]);
} else {
echo json_encode(["success" => false, "message" => "Error modify user: " . $stmt->error]);
}
}
$stmt->close();
$conn->close();
}
?>