简体   繁体   English

HTML未显示在浏览器中

[英]HTML not showing up on browser

I am writing a code in which the user is asked for username and password. 我正在编写一个代码,要求用户输入用户名和密码。 If the details provided match the details in the database, then he is displayed the data, else he is prompted with a message that the information provided is not valid. 如果提供的详细信息与数据库中的详细信息匹配,那么将向他显示数据,否则提示他一条消息,指出提供的信息无效。 Here is the part of the code that says information is not valid, 这是代码中表示信息无效的部分,

<?php if($user!=$username && $pass!=$password)
  {          
?>
<p id="intro">Invalid Information</p>
<?php 
  }
?>   

But the problem I am facing is that even if the username and password does not match, the message Invalid Information is not displayed. 但是我面临的问题是,即使用户名和密码不匹配,也不会显示消息无效信息。 Please help out. 请帮忙。 Thanks 谢谢

You need OR, not AND: 您需要OR,而不是AND:

<?php if($user!=$username || $pass!=$password) : ?>
<p id="intro">Invalid Information</p>
<?php endIf; ?>

PS I used the alternative syntax. PS我使用了替代语法。 It looks better. 看起来更好。


The reasoning for using OR and not AND, if you check for AND, only if both username AND password is wrong, the condition will evaluate to true (if one of them is correct, you will get FALSE). 使用OR而不使用AND的理由是,如果您检查AND,则仅当两个用户名AND密码均不正确时,条件才会评估为true(如果其中之一正确,则将为FALSE)。

Your logic seems to be wrong. 您的逻辑似乎是错误的。 as you are using not equals to compare with the both variables, so to what you are trying to get from the logic, you have to use || 因为您正在使用不等于值来与两个变量进行比较,所以要从逻辑中获取结果,您必须使用||。 instead of &&. 代替 &&。

 <?php if($user!=$username && $pass!=$password)
   {          
echo '<p id="intro">Invalid Information</p>';
   }
 ?>   

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

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