-2

我收到此错误,为什么它期望参数不是布尔值?我该如何解决?(我知道这是一个常见的错误,所以我想了解它为什么会出现,这样当它再次出现时我可以自己修复它。)

警告:mysqli_stmt_num_rows() 期望参数 1 为 mysqli_stmt,布尔值在 C:\Users\James\Desktop\Container\XAMPP\htdocs\Triiline1\signupuser.php 第 20 行给出

<!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>
4

2 回答 2

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));

}
于 2013-08-02T09:44:33.060 回答
0

尝试使用其中一个mysqlimysql不要混淆..你正在使用两者

$usernamesquery = mysqli_query("SELECT * FROM logins WHERE username='$username'");
if(mysqli_stmt_num_rows($usernamesquery) > 0) {
    die('This username is already taken.');
}
于 2013-08-02T09:44:15.583 回答