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>
Konsole :
You are using mysql_* in this statement instead of mysqli_*\n\n$usernamesquery = mysql_query(\"SELECT * FROM logins WHERE username='$username'\");\n\n\nTry:\n\n$usernamesquery = mysqli_query($connection, \"SELECT * FROM logins WHERE username='$username'\");\n\n\nEDIT\n\nYou need to use mysqli_num_rows($usernamesquery) instead of mysqli_stmt_num_row(...) in your current implementation:\n\nmysqli_stmt_num_rows() is used as:\n\nif ($stmt = mysqli_prepare($connection, $query)) {\n\n /* execute query */\n mysqli_stmt_execute($stmt);\n\n /* store result */\n mysqli_stmt_store_result($stmt);\n\n printf(\"Number of rows: %d.\\n\", mysqli_stmt_num_rows($stmt));\n\n}\n",
2013-08-02T09:44:33