0

我的登录脚本中出现了一个奇怪的错误。通过研究,我无法确定问题所在。我想知道是否有人可以帮助我谢谢。这是错误信息,

解析错误:语法错误,第 43 行的意外 $end。

代码

<?php
    session_start();

    if(!isset($_SESSION["user_id"])){
        header("location:../../login.html");
    }


?>
<?php
    $username = $_POST['txt_username'];
    $password = $_POST['txt_password'];
    if ($username&&$password){

        $connect = mysql_connect("server", "username", "password") or die("No Server Found");

        mysql_select_db("databse") or die("No Connection");

        $query = mysql_query("SELECT * FROM account WHERE username='$username'");
        $numrows = mysql_num_rows($query); 

        if($numrows !=0){
            while ($rows = mysql_fetch_assoc($query)){

                $dbusername = $row['username'];
                $dbpassword = $row['password'];
            }
            if ($username == $dbusername && $password == dbpassword) {
                echo "Login Successful. <a href='homepage.html'>Click Here to go to the home page</a>";
                $_SESSION['username'] = $dbusername;
            } elseif ($username == '' || $password == '') {

                die("Please enter a username and password");

            } elseif (empty($dbusername)) {

                die("This account does not exsist");

            } else {
                die("Please enter a username and password");
            }
        }

?>
4

3 回答 3

2

最后一行需要一个右大括号来关闭这个 if 语句:

if ($username&&$password){

一个体面的 IDE 应该可以解决这个问题。

$在 dbpassword 第 28 行缺少 & 需要 sanitize $username

于 2013-05-23T12:30:24.433 回答
1

您缺少最上面的 if 条件的结束右括号。你的代码应该是这样的:

<?php
    session_start();

    if(!isset($_SESSION["user_id"])){
        header("location:../../login.html");
    }


?>
<?php
    $username = $_POST['txt_username'];
    $password = $_POST['txt_password'];
if ($username&&$password){

    $connect = mysql_connect("server", "username", "password") or die("No Server Found");

    mysql_select_db("databse") or die("No Connection");

    $query = mysql_query("SELECT * FROM account WHERE username='$username'");
    $numrows = mysql_num_rows($query); 

    if($numrows !=0){
        while ($rows = mysql_fetch_assoc($query)){

            $dbusername = $row['username'];
            $dbpassword = $row['password'];
        }
        if ($username == $dbusername && $password == dbpassword) {
        echo "Login Successful. <a href='homepage.html'>Click Here to go to the home page</a>";
        $_SESSION['username'] = $dbusername;
             } elseif ($username == '' || $password == '') {

             die("Please enter a username and password");

             } elseif (empty($dbusername)) {

               die("This account does not exsist");

             } else {
                die("Please enter a username and password");
        }
    }
}

?>
于 2013-05-23T12:32:58.610 回答
0

您没有关闭其中一个 if 语句。

if ($username&&$password){  
于 2013-05-23T12:32:43.067 回答