Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Connected successfully
( ! ) Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\wamp64\www\database\db.php on line 16

What I have tried:

<pre><!DOCTYPE html>
<html>
<body>

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db";

include("connection.php");

$sql = "SELECT id, firstname, lastname FROM myguests";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
?>

</body>
</html>
Posted
Updated 28-Jan-20 17:52pm

1 solution

One possible reason seems to be that you don't investigate if the query fails. Try changing

PHP
...
if ($result = mysqli_query($conn, $sql)) {
...
 
Share this answer
 
Comments
Member 14729284 28-Jan-20 23:59pm    
Thank you for solution i tried above query after that i got this kind of result:
Connected successfully 0 results...I didn't get a table that i made in phpmyadmin(MySQL).
Wendelius 29-Jan-20 11:01am    
If the if statement returned false, it means that the query has failed. To check the syntax, run it directly in the MySQL database. Perhaps you have misspelled a column or the table

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900