我收到此错误,为什么它希望参数不是布尔值?我该如何解决? (我知道这是一个常见的错误,所以我想了解为什么会出现这种错误,以便我可以在它再次出现时自行修复它。)
警告:mysqli_stmt_num_rows()要求参数1为mysqli_stmt,布尔值在第20行的C:\ Users \ James \ Desktop \ Container \ XAMPP \ htdocs \ Triiline1 \ signupuser.php中给出
<!doctype html>
<html>
<head>
<title>User Signup</title>
</head>
<body>
<?php
include 'connect.php';
//if submit is clicked
if (isset($_POST['submit'])) {
//then check if all fields are filled
if (empty($_POST['username']) | empty($_POST['password']) | empty($_POST['firstname']) | empty($_POST['MI']) | empty($_POST['lastname']) | empty($_POST['email']) | empty($_POST['phonenumber']) | empty($_POST['country']) ) {
echo('You did not complete all of the required fields'); }
$username = $_POST['username'];
$password = $_POST['password'];
$usernamesquery = mysql_query("SELECT * FROM logins WHERE username='$username'");
if(mysqli_stmt_num_rows($usernamesquery) > 0) {
die('This username is already taken.');
}
} ?>
<form action="" method="post">
Username: <input type="text" name="username" maxlength="30"><br>
Password: <input type="password" name="password" maxlength="30"><br>
First Name: <input type="text" name="firstname" maxlength="30"><br>
Middle Initial: <input type="password" name="MI" maxlength="30"><br>
Last Name: <input type="text" name="lastname" maxlength="30"><br>
Email: <input type="password" name="email" maxlength="50"><br>
Phone Number: <input type="text" name="phonenumber" maxlength="11"><br>
Country: <input type="password" name="country" maxlength="40"><br>
<input type="submit" name="submit">
</form>
</body>
</html>
答案 0 :(得分:1)
您在此声明中使用mysql_*
而不是mysqli_*
$usernamesquery = mysql_query("SELECT * FROM logins WHERE username='$username'");
尝试:
$usernamesquery = mysqli_query($connection, "SELECT * FROM logins WHERE username='$username'");
修改强>
您需要在当前的实施中使用mysqli_num_rows($usernamesquery)
而不是mysqli_stmt_num_row(...)
:
mysqli_stmt_num_rows()
用作:
if ($stmt = mysqli_prepare($connection, $query)) {
/* execute query */
mysqli_stmt_execute($stmt);
/* store result */
mysqli_stmt_store_result($stmt);
printf("Number of rows: %d.\n", mysqli_stmt_num_rows($stmt));
}
答案 1 :(得分:0)
尝试使用mysqli
或mysql
不要混淆..你正在使用两者
$usernamesquery = mysqli_query("SELECT * FROM logins WHERE username='$username'");
if(mysqli_stmt_num_rows($usernamesquery) > 0) {
die('This username is already taken.');
}