duangu3620 2013-08-02 09:41
浏览 75
已采纳

错误:期望参数1为mysqli_stmt,给定布尔值?

I'm getting this error, why does it expect the parameter to not be a boolean? How do I fix this? (I know this is a common error, so I want to understand WHY it comes up, so that I can hopefully fix it on my own when it comes up again.)

Warning: mysqli_stmt_num_rows() expects parameter 1 to be mysqli_stmt, boolean given in C:\Users\James\Desktop\Container\XAMPP\htdocs\Triiline1\signupuser.php on line 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>
  • 写回答

2条回答 默认 最新

  • 普通网友 2013-08-02 09:44
    关注

    You are using mysql_* in this statement instead of mysqli_*

    $usernamesquery = mysql_query("SELECT * FROM logins WHERE username='$username'");
    

    Try:

    $usernamesquery = mysqli_query($connection, "SELECT * FROM logins WHERE username='$username'");
    

    EDIT

    You need to use mysqli_num_rows($usernamesquery) instead of mysqli_stmt_num_row(...) in your current implementation:

    mysqli_stmt_num_rows() is used as:

    if ($stmt = mysqli_prepare($connection, $query)) {
    
        /* execute query */
        mysqli_stmt_execute($stmt);
    
        /* store result */
        mysqli_stmt_store_result($stmt);
    
        printf("Number of rows: %d.
    ", mysqli_stmt_num_rows($stmt));
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?