简体   繁体   English

SQL返回空行

[英]SQL returning null rows

I have the below PHP code for returning the user details from the table 我有下面的PHP代码,用于从表中返回用户详细信息

<?php

$con=mysqli_connect("localhost","root","");
if(!$con)
    {
        die('Could not connect'.mysqli_error());
    }
mysqli_select_db($con,"mysql");
$username=$_POST["username"];
$password=$_POST["password"];
$statement=mysqli_prepare($con,"Select * from bbau_login where username= ? and password= ? ");
mysqli_stmt_bind_param($statement,"ss",$username,$pasword);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement,$id,$name,$username,$password);

$user=array();

while(mysqli_stmt_fetch($statement))
    {
        $user['name']=$name;
        $user['username']=$username;
        $user['password']=$password;
    }
echo json_encode($user);
mysqli_stmt_close($statement);
mysqli_close($con);

?>

But it is returning null result when I am hitting this code from the application. 但是,当我从应用程序中访问此代码时,它返回空结果。 If I run the sql with hard coded value 如果我以硬编码值运行sql

Select * from bbau_login where username= 'aqsdfg' and password= 'adjbf'

then I am getting the desired result but not with the sql specified in the php script 然后我得到了预期的结果,但没有使用php脚本中指定的sql

Also I checked I am getting the proper values in $username and $password. 我还检查了我是否在$ username和$ password中获得了正确的值。 I think i need to pass the $username and $password in quotes. 我认为我需要在引号中传递$ username和$ password。 Please can someone help in writing correct query with quotes. 请有人帮忙编写带引号的正确查询。

Well, I would think that a consistent spelling of pasword/password would help immensely: 好吧,我认为pasword/password的一致拼写将极大地帮助您:

#  vv
$password=$_POST["password"];
:
mysqli_stmt_bind_param($statement,"ss",$username,$pasword);
#                                                   ^

You may well, as you state, be "getting the proper values in $username and $password ", but that's not going to help if you don't actually use what's in $password :-) 您可能,因为你的状态,来“凑了正确的价值观$username$password ”,但是这不会帮助,如果你不实际使用什么在$password :-)

You have written incorrect spelling of password while passing it 您在传递密码时写错了正确的密码

change 更改

 mysqli_stmt_bind_param($statement,"ss",$username,$pasword);

to

mysqli_stmt_bind_param($statement,"ss",$username,$password);

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

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