解析错误:语法错误:意外的'{'

发布于 2024-11-29 07:24:57 字数 799 浏览 0 评论 0原文

我有这段代码可以处理用户然后将他们重定向到用户主页。

<?php
    $username = $_POST['username'];
    $password = $_POST['pwd'];

    $file = file_get_contents("userdb.html");
    if(!strpos($file, $username)) {
        echo "Your username was not found in our database. Please go back and try again.";
    } else {
        echo "Redirecting...";
        if (md5($password) == !strpos($file, (md5($password))) {
             echo "Redirecting..."
             header ('Location: ./userhome.php')
        } else {
             print "Whoops! Your password seems to be incorrect. Go back and try again."
        }
    }
?>

我收到错误:

Parse error: syntax error, unexpected '{' in userprocess.php on line 11

有人可以告诉我问题吗?我认为这可能是 if 语句中的 if ,但是我能做些什么来替代呢?谢谢。

I have this code that processes a user then redirects them to the user homepage.

<?php
    $username = $_POST['username'];
    $password = $_POST['pwd'];

    $file = file_get_contents("userdb.html");
    if(!strpos($file, $username)) {
        echo "Your username was not found in our database. Please go back and try again.";
    } else {
        echo "Redirecting...";
        if (md5($password) == !strpos($file, (md5($password))) {
             echo "Redirecting..."
             header ('Location: ./userhome.php')
        } else {
             print "Whoops! Your password seems to be incorrect. Go back and try again."
        }
    }
?>

And I get the error:

Parse error: syntax error, unexpected '{' in userprocess.php on line 11

Could someone tell me the problem please? I think it may be the if inside of if statement, but what can I do for an alternative? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦初启 2024-12-06 07:24:57

首先,这一行缺少一个右括号:

if (md5($password) == !strpos($file, (md5($password))) {

计算 () 的数量——它们需要匹配。

当您修复此问题时,您仍然会收到错误,因为 PHP 语句需要以分号结尾。

以下所有行都缺少分号:

echo "Redirecting..."
header ('Location: ./userhome.php')
print "Whoops! Your password seems to be incorrect. Go back and try again."

您需要先修复它们,然后才能在没有语法错误的情况下运行程序。

希望有帮助。

Firstly, this line is missing a closing bracket:

if (md5($password) == !strpos($file, (md5($password))) {

Count the number of ( and ) -- they need to match.

When you fix this, you'll still get errors, because PHP statements need to end with semi-colons.

All of the following lines are missing their semi-colon:

echo "Redirecting..."
header ('Location: ./userhome.php')
print "Whoops! Your password seems to be incorrect. Go back and try again."

You need to fix them all before you'll be able to run the program without syntax errors.

Hope that helps.

时间你老了 2024-12-06 07:24:57

您在该行中缺少右括号:

if (md5($password) == !strpos($file, (md5($password))) {

You are missing a right parenthesis in the line:

if (md5($password) == !strpos($file, (md5($password))) {
心的憧憬 2024-12-06 07:24:57
<?php
    $username = $_POST['username'];
    $password = $_POST['pwd'];

    $file = file_get_contents("userdb.html");
    if(!strpos($file, $username)) {
        echo "Your username was not found in our database. Please go back and try again.";
    } else {
        echo "Redirecting...";
        if (md5($password) == !strpos($file, md5($password))) {
             echo "Redirecting...";
             header ('Location: ./userhome.php');
        } else {
             print "Whoops! Your password seems to be incorrect. Go back and try again.";
        }
    }
?>
<?php
    $username = $_POST['username'];
    $password = $_POST['pwd'];

    $file = file_get_contents("userdb.html");
    if(!strpos($file, $username)) {
        echo "Your username was not found in our database. Please go back and try again.";
    } else {
        echo "Redirecting...";
        if (md5($password) == !strpos($file, md5($password))) {
             echo "Redirecting...";
             header ('Location: ./userhome.php');
        } else {
             print "Whoops! Your password seems to be incorrect. Go back and try again.";
        }
    }
?>
树深时见影 2024-12-06 07:24:57

更改

if (md5($password) == !strpos($file, (md5($password)))

if (md5($password) == !strpos($file, md5($password)))

Change

if (md5($password) == !strpos($file, (md5($password)))

to

if (md5($password) == !strpos($file, md5($password)))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文