<code>if($row){ //判断密码是否正确 if($row['user_password']===$password){ echo 1; }else{ echo "密码错误"; } }else{ echo "没找到用户名"; } </code>
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?
<code>if($row){ //判断密码是否正确 if($row['user_password']===$password){ echo 1; }else{ echo "密码错误"; } }else{ echo "没找到用户名"; } </code>
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?
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>
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