PHP If-Statements不适用于表单

时间:2012-10-21 05:59:07

标签: php forms if-statement

我得到了意想不到的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";
}
?>

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

问题:问题是什么

3 个答案:

答案 0 :(得分: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.";
}

请注意,我只是尝试修复语法问题,我无法猜测脚本的逻辑。

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

答案 1 :(得分: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.";
    }
    ?>

答案 2 :(得分: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";
 }