HI,

I have the below php code that i am attempting to use to search the database for a value that has been inputted in the form. This connects to the database and works fine but brings back no results. I found the following error:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/vhosts/dylan.simplyms.com/httpdocs/Search-Call.php on line 18 0 results

<?php
ini_set('display_errors', 1); error_reporting(E_ALL);
$servername = "localhost";
$username = "Dylanc";
$password = "xxxx";
$dbname = "FirstAttempt";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
} 

$sql = "SELECT client_id, domain, comments FROM FirstAttempt";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "Client ID: " . $row["client_id"]. " - Domain: " . $row["domain"]. "Comments:" . $row["comments"];
    }
} else {
    echo "0 results";
}
$conn->close();
?>

I am relatively new to php, does anyone have any ideas?

Recommended Answers

All 3 Replies

Member Avatar for diafol

It's telling you that $resultis a boolean value - most likely false. This will be due to the fact that there is something wrong with the $conn link (connection) or the actual $sql query. As you have no error on the creation of the link, then it's more likely to be the query itself. You can trap errors on the query function too - in fact this is very useful.

http://php.net/manual/en/mysqli.error.php

Something like ...

$result = mysqli_query($conn, $sql);
if (!$result) {
    printf("Errormessage: %s\n", mysqli_error($conn));
}

You can write a slicker version of the code above, but I think this explains it a little better.

Hi, try this

$sql = "SELECT `client_id`, `domain`, `comments` FROM `FirstAttempt`";

echo the query. copy paste it to mysql to see whats worng with the query . my mony on the table name

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.