简体   繁体   English

PHP If语句不适用于表单

[英]PHP If-Statements Not Working for Form

I am getting unexpected T_ELSES. 我收到意外的T_ELSES。 Please help 请帮忙

<?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";
}
?>

Either it is just saying please click submit or it gives me unexpected errors or it doesn't detect please fill in all fields. 它只是说请单击“提交”,否则会给我带来意外错误,或者没有检测到请填写所有字段。 Please help me and fix up my code thanks 请帮助我并修复我的代码,谢谢

Question: Whats the problem 问题:出了什么问题

It seems to me you require something like this: 在我看来,您需要这样的东西:

<?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.";
}

Note that I am only attempting to fix syntactical issues, I cannot guess the logic of your script. 请注意,我只是在尝试解决语法问题,我无法猜测脚本的逻辑。

I have updated to reflect your comment. 我已经更新以反映您的评论。

<?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.";
    }
    ?>

As a solution to your problem please refer the code snippet mentioned below 为了解决您的问题,请参考下面提到的代码段

    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";
 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM