-5

这是我的代码:

    <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>

我得到一个解析错误:

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

4

4 回答 4

5

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

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

请参阅echo 示例以获得更好的理解。

于 2013-09-03T14:10:19.023 回答
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,使用&&

于 2013-09-03T14:15:40.070 回答
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>
于 2013-09-03T14:14:51.763 回答
0

双引号(")问题:

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

你可以这样做:

echo "You are logged in as {$username}";
于 2013-09-03T14:16:16.030 回答