0

I am trying to output(show) some values from my database then later get my hands dirty on with it.

I wrote a custom code with mysqli but each time I run the page it gives me error mesage saying :

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\christembassy\controlscript.php on line 30

the line 30 on my code is this : if(mysqli_num_rows($result) > 0)

And this is the whole code:

<?php
//setting connection variables
$hostname = "localhost";
$username= "root";
$password ="";
$db= "cemembers";

//opening connection go database
$mysqli_db = mysqli_connect($hostname, $username, $password, $db);

//check connection
if(mysqli_connect_errno()) {
    printf("Connect Failed: %s\n", mysqli_connect_errno());
    exit();
}

$sql = "SELECT FristName, LastName, Occupation FROM users"; 
$result = mysqli_query($mysqli_db, $sql);

if(mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo  ' Name: $row["FirstName"]. $row["LastName"] ."<br>" Cell: $row["Occupation"]'."<br>";
    }
} else {
    echo(" 0 Results found");
}

mysqli_close($mysqli_db);
?>

Please any help would be much appreciated.

prava
  • 3,916
  • 2
  • 24
  • 35
  • It looks like `$result` is `false` in this case, rather that the resource it was expecting, because the query is invalid. – halfer Mar 17 '15 at 06:09

1 Answers1

1
SELECT FristName, LastName, Occupation FROM users

99% i am sure you meant,

SELECT FirstName, LastName, Occupation FROM users

take care of the typos.

itachi
  • 6,323
  • 3
  • 30
  • 40