A small problem with PHP about login

WBOY
Release: 2016-10-10 11:56:00
Original
1003 people have browsed it

<code>if($row){
   //判断密码是否正确
   if($row['user_password']===$password){
       echo 1;
   }else{
       echo "密码错误"; 
   }
}else{
   echo "没找到用户名";    
}
</code>
Copy after login
Copy after login

The above code is used to verify whether the user name and password entered by the user are correct. For the sake of convenience, I have simplified the code and removed the content of obtaining database data. Why does it output "User not found" when nothing is entered after opening the page?
A small problem with PHP about login

Reply content:

<code>if($row){
   //判断密码是否正确
   if($row['user_password']===$password){
       echo 1;
   }else{
       echo "密码错误"; 
   }
}else{
   echo "没找到用户名";    
}
</code>
Copy after login
Copy after login

The above code is used to verify whether the user name and password entered by the user are correct. For the sake of convenience, I have simplified the code and removed the content of obtaining database data. Why does it output "User not found" when nothing is entered after opening the page?
A small problem with PHP about login

if($row) This piece of code needs to be written in the POST request code block. In this way, this code will not be executed when getting.

For example, after clicking login, the submitted user and password fields are: username password

<code>$username = isset($_POST['username']) ? $_POST['username'] : false;
$password = isset($_POST['password']) ? $_POST['password'] : false;

if($username && $password){
    if($row){
       //判断密码是否正确
       if($row['user_password']===$password){
           echo 1;
       }else{
           echo "密码错误"; 
       }
    }else{
       echo "没找到用户名";    
    }
}
</code>
Copy after login

Print out $row to see what it is

That means this code is executed when you open the webpage, and the if judgment is false

Since the user is not found after printing, it means $row is false, then you should focus on the code to obtain $row instead of focusing on the posted code

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!