Larry Ullman's Book Forums

Mysqli_Num_Rows() Expects Parameter 1 To Be Mysqli_Result, Boolean Given Array

Recommended Posts

I'm running PHP files of example 2 from my computer and I got those following errors across pages.

An error occurred in script 'D:\XAMPP\htdocs\ex2\html\views\home.html' on line 14:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
Array

An error occurred in script 'D:\XAMPP\htdocs\ex2\html\shop.php' on line 32:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
Array

An error occurred in script 'D:\XAMPP\htdocs\ex2\html\sales.php' on line 20:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
Array

An error occurred in script 'D:\XAMPP\htdocs\ex2\html\wishlist.php' on line 80:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
Array

An error occurred in script 'D:\XAMPP\htdocs\ex2\html\cart.php' on line 81:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
Array

Can someone please tell me how to fix it? Thanks.

Share on other sites

Try running the query directly on the DB itself, either through phpMyAdmin or the command line.

Share on other sites

Awesome Hartley. I made the php files work finally. It's my fault when I didn't create stored procedures as guidance in Larry's book at first. You're always helpful Hartley. Thank you.

Thanks.

Share on other sites

• 5 months later...

I am also running into the same problem the  difference  however, is that am running mine on a live server.

So my error is as follow:

An error occurred in script '/home/content/82/11778682/html/shop/views/home.html' on line 9:
mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given

This is what line 9 actually looks like:

// If records are returned, include the view:
if (mysqli_num_rows($r) > 0) { echo '<dl class="special fright"> <dt><a href="/shop/sales/">Sale Items</a></dt>'; // Fetch each item: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<dd><a href="/shop/sales/#' .$row['sku'] . '" title="View This Product"><img alt="" src="/products/' . $row['image'] . '" /><span>' .$row['sale_price'] . '</span></a></dd>';
}

echo '</dl>';

I would really appreciate it if you can help me resolve this issue.
Share on other sites

That means your SELECT query isn't working. You'll need to run it separately on the server to see what the results are.

Share on other sites

• 4 years later...

I am also getting an error in my code while searching something..

I am sending my code please check it once and then revert me back with the correct code.

<?php
$result = mysqli_query($con,"SELECT * FROM packages WHERE Name, Cities, Destinations, Duration");
$rows = mysqli_num_rows($result);
echo $rows; ?> Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\search\bar.php on line 29 this error is coming .. please resolve this error Link to comment Share on other sites That means your SELECT query isn't working. You'll need to run it separately on the server to see what the results are. Hint: the problem is syntactical, from "WHERE" on. Link to comment Share on other sites • 4 months later... I am also getting an error with my code while trying to display something on the page The error is WARNING: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\xampp\htdocs\ECE\ramonsys\include\database.php on line 98 the code is public function num_rows() {$cur = $this->executeQuery(); return mysqli_num_rows($cur));

}

what can I do to fix the problem? Thank you!

Share on other sites

That means your SELECT query isn't working. You'll need to run it separately on the server to see what the results are (i.e., what the error is).

Share on other sites

• 4 weeks later...

I am having the same problem however if i run my sql code on the DB it works.

<!DOCTYPE html>
<!--
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<meta charset="UTF-8">
<title></title>
<body>
<?php

$user_name= "11";$conn = mysqli_connect('localhost', "root", "", "Invoices");

if (!$conn){ echo "Cannot find database"; } else {$mysql1 = "SELECT Invoice_ID, Served_by, Date_served, Time_served, Cost FROM payment WHERE Invoice_ID like '.$user_name''";$result = mysqli_query($conn,$mysql1);
mysqli_store_result($conn);$numrows = mysqli_num_rows($result); } if ($numrows > 0) {

}
else {
}

?>
</body>
</html>

Share on other sites

Invoke the mysqli_error() function to have PHP spit out the MySQL error that occurred.

Share on other sites

• 3 weeks later...
On 3/20/2019 at 9:01 PM, Larry said:

That means your SELECT query isn't working. You'll need to run it separately on the server to see what the results are (i.e., what the error is).

<?php
$conn=mysqli_connect ("localhost", "root", ""); if (!$conn) {
echo "server connction error";
}
$db_conn = mysqli_select_db($conn, "test2");
$sql = "select id, name, email, passwd from f_user";$query = mysqli_query($conn,$sql);

?>
<table>
<tr>
<td><strong>email</strong></td>
<td><strong>Passwd</strong></td>
<td><strong>Action</strong></td>
</tr>
<?php
if (mysqli_num_rows($query)>=1){ while ($row=mysqli_fetch_assoc($query)){ ?> <tr> <td><?php echo$row['name'];?></td>
<td><?php echo $row['email'];?></td> <td><?php echo$row['passwd'];?></td>
<td><a href="edit.php?id=<?php echo $row['id'];?>"> Edit</a> I <a href ="delete.php?id=<?php echo$row['id']; ?>">Delete</a></td>
</tr>
<?php
}}
?>
</table>

Share on other sites

Please help me I am also getting the warning on above quote as mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\Mypractice\Old practice file\edit.php.php on line 20

Share on other sites

That means your SELECT query isn't working. You'll need to run it separately on the server to see what the results are (i.e., what the error is).

or

Invoke the mysqli_error() function to have PHP spit out the MySQL error that occurred.

Share on other sites

• 7 months later...

It's not a matter of secrets. Forums like these or Stack Overflow are here expressly to share information and to help others. Honestly, the absolutely best thing to do would be to use mysqli_error() b/c then MySQL will tell you what the problem is, whereas we're just guessing. But without that knowledge my best guess would be that the PHP user for the script doesn't have execute permissions to run the stored procedure. Or you have the database wrong. In either case, mysqli_error() should tell you the actual cause.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.