function isValidUser($dbc,$email)
{
$sql=sprintf("select id from user where email = '%s' and password ='%s' ", $_POST['email'],$_POST['password'] );
$qresult = mysqli_query($dbc,$sql);//line 18
$test = mysqli_fetch_array($qresult);//line 19
echo $test[0];
if(mysqli_num_rows($qresult)>0)//line21
{
echo "User Exists";
return true;
}
else
{
echo "Not a User";
return false;
}
}
我想也许我有一些范围问题(根据类似问题的其他stackoverflow响应)。但我似乎不明白。我是php的新手。可以有人告诉我如何纠正这个。?
mysqli_query() expects parameter 1 to be mysqli, object given in... line 18
mysqli_fetch_array() expects parameter 1 to be mysqli, null given in line 19
mysqli_num_rows() expects parameter 1 to be mysqli, null given in line 21
答案 0 :(得分:-1)
试试这个:
function isValidUser($dbc,$email)
{
$email = $_POST['email'];
$host = "";
$username = "";
$password_mysql = "";
$database ="";
$password = $_POST['password'];
$link = mysqli_connect($host, $username, $password_mysql, $database); /* hard code the connection variables in to test if something is wrong here. */
$sql="select id from user where email = '".$email."' and password ='".$password."'";
$qresult = mysqli_query($link,$sql);//line 18
$test = mysqli_fetch_array($qresult, MYSQLI_BOTH);//line 19
while($test = mysqli_fetch_array($qresult, MYSQLI_BOTH)){
echo $test['id']."<br>";
};
if(mysqli_num_rows($qresult)>0)//line21
{
echo "User Exists";
return true;
}
else
{
echo "Not a User";
return false;
}
}