Muhammad Arslan Muhammad Arslan - 1 year ago 125
MySQL Question

mysqli_fetch_object() expects parameter 1 to be mysqli_result, boolean

I am trying to get data from database but I can't, this error occurs and I can't understand what is the problem.

Here is my code for getting data:

$sql = " select id from rating_system where user_id = $ipaddress ";
$result = mysqli_query($conn, $sql);
$row = mysqli_fetch_object($result);

Here is my code for database connection:

$conn = new mysqli('localhost', 'root', '', 'star_rating');

if ($conn->connect_error) {
die('Connect Error: ' . $con->connect_error);

Answer Source

Try with:

$row = $result -> mysqli_fetch_object();

If you have more than a record you should put the method in a while() cycle for getting all the data:

while($row = $result -> mysqli_fetch_object()){
      echo $row -> 'field_name_1;
      echo $row -> 'field_name_...';
      echo $row -> 'field_name_n;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download