我正在尝试检查我的模拟Twitter项目上的riegistration是否存在句柄或电子邮件我称之为bleeter,但我收到此错误:
注意:类mysqli_result的对象无法在第20行的first.php中转换为int
这是我检查num_rows_handle == 0
的行。我该怎么做?
$query_check_handle = "SELECT * FROM users WHERE handle = " . $handle;
$num_rows_handle = mysqli_query($dbc, $query_check_handle);
if ($num_rows_handle == 0) { // Line 20
//check email
$query_check_email = "SELECT * FROM users WHERE email = " . $email;
$num_rows_email = mysqli_query($dbc, $query_check_email);
if ($num_rows_email == 0) {
$query_register = "INSERT INTO users (first_name, last_name, handle, password, email, ACL)
VALUES ('$fname', '$lname', '$handle', '$pass', '$email', '$ACL')"
or DIE ("error running the query.");
mysqli_query($dbc, $query_register);
echo "<br>";
echo "You have succesfully registered, please login";
} else {
echo "<br>";
echo "Email already in use. Please try again";
}
} else {
echo "<br>";
echo "Handle already in use. Please try again";
}
答案 0 :(得分:0)
当查询为SELECT
时,mysqli_query
会返回类型为mysqli_result
的对象,其对象的属性num_rows
包含行数。因此
$result = mysqli_query($dbc, $query_check_email);
$num_rows_email = mysqli_num_rows($result);