解析错误。意外的文件结束。 (PHP)

时间:2013-09-03 14:09:23

标签: php

这是我的代码:

    <html>
    <head>
        <title>
        </title>
    </head>
    <body>
        <?php
            $username = $_POST['username'];
            $password = $_POST['password'];

            if (($username=="x")AND($password=="y"))
            {
                echo "You are logged in as".$username.";
            }
        ?>
    </body> 
</html>

我得到一个解析错误:

  

解析错误:语法错误,意外的文件结束,期望变量   (T_VARIABLE)或$ {(T_DOLLAR_OPEN_CURLY_BRACES)或{$(T_CURLY_OPEN)   第17行

4 个答案:

答案 0 :(得分:5)

您的echo使用不正确,您有双重引用"问题:

echo "You are logged in as " . $username;

有关更好的理解,请参阅echo examples

答案 1 :(得分:2)

您要么错过",要么还有一个"

echo "You are logged in as".$username.";

可以成为

echo "You are logged in as".$username."";

echo "You are logged in as".$username;

甚至更好的解决方案:

echo "You are logged in as {$username}";

为了更好地阅读您的代码,请不要使用AND,请使用&&

答案 2 :(得分:0)

这是完全固定的代码。

<html>
    <head>
        <title>
        </title>
    </head>
    <body>
        <?php
            $username = $_POST['username'];
        $password = $_POST['password'];

            if (($username=="x")AND($password=="y"))
            { 
                echo "You are logged in as".$username;
            }
        ?>
    </body>
</html>

答案 3 :(得分:0)

双引号(")问题:

echo "You are logged in as".$username.";

你可以这样做:

echo "You are logged in as {$username}";