我试图登录到管理面板,但得到解析错误。
Parse error: syntax error, unexpected '{', expecting '('
实际上,我已经使用了条件,如果用户角色是管理员,那么它应该打开一个页面,如果用户角色等于员工,它应该打开该页面。
但是它得到了这个error.If我试着这样做
<?php session_start();
include '../includes/db.php';
if(isset($_POST['submit_login'])){
if(!empty($_POST['user_name']) && !empty($_POST['password'])){
$get_user_name = mysqli_real_escape_string($conn,$_POST['user_name']);
$get_password = mysqli_real_escape_string($conn,$_POST['password']);
$sql = "SELECT * FROM users WHERE username = '$get_user_name' AND user_password = '$get_password' AND user_role='admin'";
if($result = mysqli_query($conn,$sql)){
while($rows = mysqli_fetch_assoc($result)){
if(mysqli_num_rows($result) == 1){
$_SESSION['user'] = $get_user_name;
$_SESSION['password'] = $get_password;
$_SESSION['user_role'] = $rows['user_role'];
header('Location:../admin/index.php');
}
elseif{
header('Location:../admin/employeeindex.php');
}
else {
header('Location:../index.php?login_error=wrong');
}
}
}
else {
header('Location: ../index.php?login_error=query_error');
}
} else {
header('Location:../index.php?login_error=empty');
}
}else {
}
?>
发布于 2018-06-21 05:37:55
$sql = "SELECT * FROM users WHERE username = '$get_user_name' AND user_password = '$get_password'" ;
if($result = mysqli_query($conn,$sql)){
while($rows = mysqli_fetch_assoc($result)){
if(mysqli_num_rows($result) == 1){
$_SESSION['user'] = $get_user_name;
$_SESSION['password'] = $get_password;
$_SESSION['user_role'] = $rows['user_role'];
if($_SESSION['user_role'] === 'admin'){
header('Location:../admin/index.php');
}
else{
header('Location:../admin/employeeindex.php');
}
}
else{
header('Location:../index.php?login_error=wrong');
}
}
}
使用上面的代码,它将成功运行。
发布于 2018-06-21 04:39:11
elseif
块中缺少条件,这就是引发语法错误的原因
elseif (condition missing here ){
header('Location:../admin/employeeindex.php');
}
有关条件语法的更多信息,请单击此处http://php.net/manual/en/control-structures.elseif.php
发布于 2018-06-21 04:45:54
elseif(mysqli_num_rows($result) != 1){
header('Location:../admin/employeeindex.php');
}
使用这段代码,它将会工作。
https://stackoverflow.com/questions/50956628
复制相似问题