Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
Jane39

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 this post


Link to post
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. :)

Share this post


Link to post
Share on other sites

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 this post


Link to post
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 this post


Link to post
Share on other sites

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

Share this post


Link to post
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. 

Share this post


Link to post
Share on other sites

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 this post


Link to post
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 this post


Link to post
Share on other sites

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

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        
        // put your code here
        $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) {
           
             echo "Login succesful";
           
       }
             else {
                   echo "User not found or invalid credentials";
       }
       
       
       
       ?>
    </body>
</html>

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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
//reading the database
$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>username</strong></td>
            <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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Loading...
Sign in to follow this  

×
×
  • Create New...