我正在创建几行来检查数据库中是否存在用户。为此,我只是在数据库中找到用户名,如果数据库中有一个具有该名称的用户,则使用num_rows表明他们是具有该名称的用户。
错误是:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result,
boolean given in /home/bluef/public_html/SMNS/register.php on line 36
代码:
$usernamef = mysqli_query($link, "SELECT * FROM Users
WHERE Username =".$Username."");
$usernamefound = mysqli_num_rows($usernamef);
if($usernamefound != 0){
echo "Username in use, try another username?";
}
答案 0 :(得分:1)
始终在mysqli_connect
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
答案 1 :(得分:-1)
尝试使用您的查询
$usernamef = mysqli_query($link, "SELECT * FROM Users
WHERE Username =".$Username."") or die(mysqli_error());
查看错误。你也可以尝试这个
$usernamef = mysqli_query($link, "SELECT COUNT(*) AS myCount FROM Users
WHERE Username =".$Username."") or die(mysqli_error());
$row = mysqli_fetch_array($usernamef)
if( $row['myCount '] > 0 )
{
echo "Username in use, try another username?";
}
点击此链接http://www.w3schools.com/php/func_mysqli_error.asp
你也可以试试mysql_query和mysql_num_rows()而不是mysqli_query()