我有以下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);
?>
但是当我从应用程序中获取此代码时,它返回null结果。 如果我运行带有硬编码值的SQL
Select * from bbau_login where username= 'aqsdfg' and password= 'adjbf'
然后我得到了所需的结果,但没有使用php脚本中指定的sql
此外,我检查了我在$ username和$ password中获取了正确的值。 我想我需要在引号中传递$ username和$ password。请有人帮忙用引号撰写正确的查询。
答案 0 :(得分:0)
传递密码时,您写的密码拼写错误
变化
mysqli_stmt_bind_param($statement,"ss",$username,$pasword);
到
mysqli_stmt_bind_param($statement,"ss",$username,$password);