解析错误:语法错误,意外' {'在第13行的C:\ xampp \ htdocs \ multiusers \ users \ user_Validate.php中

时间:2017-12-09 04:47:43

标签: php

它似乎是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>";
    }
?>

2 个答案:

答案 0 :(得分:0)

else($role=="student") change this to else if ($role=="student")

否则不能有条件Php Doc

答案 1 :(得分:0)

您的错误位于else

else从来没有条件,你把条件放在这里。

你有两种方式

  1. 仅使用else
  2. 使用elseif($ role ==&#34; student&#34;)。
  3. 代码如下

        <?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>";
        }
    ?>