-1

我得到了意想不到的 T_ELSES。请帮忙

<?php
$password = $_POST['password'];
$submit = $_POST['submit'];
if ($password == "lol") {
 if ($password) {
  if ($submit) {
   echo "Logged in";
   }
  } else {
  echo "Wrong Pass";
  }
  } else {
  echo "Please fill in all fields.";
  }
 } else {
 echo "Please click submit";
}
?>

要么只是说请点击提交,要么它给我意外的错误,或者它没有检测到请填写所有字段。请帮助我并修复我的代码谢谢

问:有什么问题

4

3 回答 3

2

在我看来,您需要这样的东西:

<?php
$password = $_POST['password'];
$submit   = $_POST['submit'];
if ($password) {
    if ($password == "lol") {
        if ($submit) {
            echo "Logged in";
        } else {
            echo "Please click submit";
        }
    } else {
        echo "Wrong Pass.";
    }
} else {
    echo "Please fill in all fields.";
}

请注意,我只是在尝试解决语法问题,我无法猜测您脚本的逻辑。

我已更新以反映您的评论。

于 2012-10-21T06:05:37.203 回答
0
<?php
    $password = $_POST['password'];
    $submit = $_POST['submit'];

    if ($password == "lol") 
    {
        if ($password) 
        {
            if ($submit) 
            {
                    echo "Logged in";
            }
        } 
        if(!$password)
        {
                echo "Wrong Pass";
        }
    } 
    if(!$password !== "lol")
    {
                echo "Please fill in all fields.";
    }
    ?>
于 2012-10-21T06:06:45.543 回答
0

作为您的问题的解决方案,请参考下面提到的代码片段

    if(!empty($submit))
    {
  if(!empty($password))
  {
     if($password=='lol')
     {
        echo "Logged in";
      }
     else
     {
         echo "Wrong Pass";
     }
  }
  else
  {
     echo "Please fill in all fields.";
   }
}
else
{
echo "Please click submit";
 }
于 2012-10-21T06:24:38.857 回答