Jane39 Posted March 29, 2014 Share Posted March 29, 2014 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 givenArray 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 givenArray 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 givenArray 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 givenArray 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 givenArray Can someone please tell me how to fix it? Thanks. Link to comment Share on other sites More sharing options...
HartleySan Posted March 29, 2014 Share Posted March 29, 2014 Your query is probably invalid. Try running the query directly on the DB itself, either through phpMyAdmin or the command line. 2 Link to comment Share on other sites More sharing options...
Jane39 Posted March 31, 2014 Author Share Posted March 31, 2014 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. Link to comment Share on other sites More sharing options...
HartleySan Posted March 31, 2014 Share Posted March 31, 2014 Glad you solved the problem. Thanks. Link to comment Share on other sites More sharing options...
Stx Posted September 5, 2014 Share Posted September 5, 2014 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. Link to comment Share on other sites More sharing options...
Larry Posted September 5, 2014 Share Posted September 5, 2014 That means your SELECT query isn't working. You'll need to run it separately on the server to see what the results are. Link to comment Share on other sites More sharing options...
Honey Agrawal Posted October 31, 2018 Share Posted October 31, 2018 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 More sharing options...
Larry Posted October 31, 2018 Share Posted October 31, 2018 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 More sharing options...
Nakashima Posted March 19, 2019 Share Posted March 19, 2019 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! Link to comment Share on other sites More sharing options...
Larry Posted March 20, 2019 Share Posted March 20, 2019 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). Link to comment Share on other sites More sharing options...
Mikeogada Posted April 12, 2019 Share Posted April 12, 2019 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> Link to comment Share on other sites More sharing options...
Larry Posted April 12, 2019 Share Posted April 12, 2019 Invoke the mysqli_error() function to have PHP spit out the MySQL error that occurred. Link to comment Share on other sites More sharing options...
rajeshkhare Posted April 30, 2019 Share Posted April 30, 2019 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> Link to comment Share on other sites More sharing options...
rajeshkhare Posted April 30, 2019 Share Posted April 30, 2019 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 Link to comment Share on other sites More sharing options...
Larry Posted April 30, 2019 Share Posted April 30, 2019 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. Link to comment Share on other sites More sharing options...
Larry Posted December 15, 2019 Share Posted December 15, 2019 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. Link to comment Share on other sites More sharing options...
Recommended Posts