它似乎是if else
语句中的错误,但我无法追踪该错误。
任何人都可以帮我解决这个错误。
<?php
session_start();
include("dbconfig.php");
$table ="";
$rurl="";
extract($_REQUEST);
if($role =="staff"){
$table="multiusers_staff";
$rurl="staff/trainer.php";
}
else($role=="student"){
$table="multiusers_student";
$rurl="student/suexecute.php";
}
$mail = $role."_email";
$uname = $role."_username";
$pass = $role."_password";
echo $check1="SELECT * FROM $table WHERE $mail ='$uemail' AND $pass ='$upwd' ";
$login1 = $con->query($check1);
$login_result1 = $login1->num_rows;
$row1 = mysqli_fetch_array($login1);
if(is_array($row1)) {
$_SESSION['s_usersid'] = $row1[0];
$_SESSION['s_userrole'] = $role;
$_SESSION['s_usersemail'] = $row1[$mail];
$_SESSION['s_usersname'] = $row1[$uname];
}
else{
echo $con->error;
}
if(isset($_SESSION["s_usersemail"])) {
echo "<script>window.location.assign('".$rurl."')</script>";
}
?>
答案 0 :(得分:0)
else($role=="student") change this to else if ($role=="student")
否则不能有条件Php Doc
答案 1 :(得分:0)
您的错误位于else
else
从来没有条件,你把条件放在这里。
你有两种方式
else
。代码如下
<?php
session_start();
include("dbconfig.php");
$table ="";
$rurl="";
extract($_REQUEST);
if($role =="staff"){
$table="multiusers_staff";
$rurl="staff/trainer.php";
}
else{ //Or use elseif with condition `elseif($role=="student"){`
$table="multiusers_student";
$rurl="student/suexecute.php";
}
$mail = $role."_email";
$uname = $role."_username";
$pass = $role."_password";
echo $check1="SELECT * FROM $table WHERE $mail ='$uemail' AND $pass ='$upwd' ";
$login1 = $con->query($check1);
$login_result1 = $login1->num_rows;
$row1 = mysqli_fetch_array($login1);
if(is_array($row1)) {
$_SESSION['s_usersid'] = $row1[0];
$_SESSION['s_userrole'] = $role;
$_SESSION['s_usersemail'] = $row1[$mail];
$_SESSION['s_usersname'] = $row1[$uname];
}
else{
echo $con->error;
}
if(isset($_SESSION["s_usersemail"])) {
echo "<script>window.location.assign('".$rurl."')</script>";
}
?>