意外的'其他' (T_ELSE)

时间:2017-03-28 14:45:59

标签: php

如果信息不正确,我试图将我的登录信息重定向到其他页面。似乎else语句不正确。请帮我!谢谢

  

语法错误,意外'其他' (T_ELSE)

<?php
$host="localhost";
$username="root";
$password="";
$dbname="oims2_db";
$tbl_name="administrator_tbl";
$tbl_name2="employee_tbl";
mysql_connect($host,$username,$password) or die("error for connect");
mysql_select_db($dbname) or die("error");

$AdminI = $_POST['AdminI'];
$AdminU = $_POST['AdminU'];
$AdminP = $_POST['AdminP'];

$sql="SELECT * FROM $tbl_name WHERE Admin_ID='$AdminI' and Admin_Username='$AdminU' and Admin_Password='$AdminP'";
$result=mysql_query($sql);
$count= mysql_num_rows($result);

$_SESSION["login_val"] = $count;

if($count==1)
{
echo "login successful " . $_SESSION{"login_val"};
header("location:1home.php");
}

 $mysqli="SELECT * FROM $tbl_name2 WHERE Emp_ID='$AdminI' and Emp_Firstname='$AdminU' and Emp_Lastname ='$AdminP'";

    $result1=mysql_query($mysqli);
$count1= mysql_num_rows($result1);
$_SESSION1["login_val1"] = $count1;


else
{
    header("location:1portal.php");

}

?>

1 个答案:

答案 0 :(得分:0)

代码的最后一部分应如下所示:

$mysqli="SELECT * FROM $tbl_name2 WHERE Emp_ID='$AdminI' and Emp_Firstname='$AdminU' and Emp_Lastname ='$AdminP'";

$result1=mysql_query($mysqli);
$count1= mysql_num_rows($result1);
$_SESSION1["login_val1"] = $count1;
if($count==1)
    {
    echo "login successful " . $_SESSION["login_val"];
    header("location: 1home.php");
    exit;
    }

    else
    {
        header("location: 1portal.php");
        exit;
    }    


    ?>

else 语句应始终紧跟在 if 语句后面。之间应该没有代码。

另外我注意到你还在使用 mysql ,现在已经被删除了。请改用mysqli or PDO