检查查询是否返回任何信息


Checking if a query returns any information

我已经为此工作了几个小时,似乎不明白为什么它不起作用。

我看过的所有教程都表明这很有效。num_rows的输出大于1,但它仍然在if语句中。

此外,即使应该是0,它也会返回1。也许是BOOL

if($test = mysqli_num_rows($result) == 0){
    echo "Username and Email are Available test= $test";
} else {
    echo "Username and Email are TAKEN";
}

只有当num_rows等于1时,您的语句才计算为true

if($test = mysqli_num_rows($result) == 0){

您需要将其更改为大于等于1或大于0:

if(mysqli_num_rows($result) >= 1){
    echo "Username and Email are Available test= $test";
} else {
    echo "Username and Email are TAKEN";
}

mysqli_num_rows():的使用

返回结果集中的行数。