我正在制作一个代码,系统会检查您是否是“管理员”。或者是“超级明星”。
我似乎无法让它循环一切,以检查是否' SuperAdmin'在' user_type'
$sql = "SELECT * from users";
$result = mysqli_query($con,$sql);
while ($row2 = mysqli_fetch_array($result)) {
if ($row2['user_type'] != "SuperAdmin") {
echo "<script>window.alert('You do not have administrative
priviledges for this page!');
location.href='../admin_page.php';</script>";
} else {
}
}
答案 0 :(得分:0)
答案 1 :(得分:0)
我相信您要检查当前使用的是“管理员”还是“超级管理员”。在这种情况下,您需要使用在对用户进行身份验证后获得的UserID来获取当前用户的行。将您的查询和PHP代码更改为:
$UserId = 111; //This is the user id from database you get on authenticating the user: e.g. 111.
$sql = "SELECT * from users WHERE UserId = ". $UserId;
$result = mysqli_query($con,$sql); //This should retrieve a single row, with details for the specific user.
while ($row2 = mysqli_fetch_array($result)) {
if !(($row2['user_type'] == "SuperAdmin")||($row2['user_type'] == "Admin")){
echo "<script>window.alert('You do not have administrative
priviledges for this page!');
location.href='../admin_page.php';</script>";
} else {
//Code to be executed if the user is an admin or a super admin
}
}