0

I am getting a

Notice: Trying to get property 'num_rows' of non-object

I have attached the codes and screenshots below

Help would be highly appreciated..

P.S: The connection is successful

<?php

include 'dbconnect.php';

$sql="SELECT * FROM review";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    echo "id: " . $row["Titleno"];
  }
}
else {
  echo "0 results";
}


mysqli_close($conn);
?>

PHPMYADMIN Screenshot PHPMYADMIN

Ayubhai Shah
  • 97
  • 10
  • You should use proper error handling first: `if($result = $conn->query($sql)) { ... } else { printf("Error message: %s\n", $conn->error); }`. Before you try to count rows, make sure there's something to count. – icecub Oct 25 '20 at 11:58
  • @icecub FYI, `printf("Error message:` is anything but a proper error handing. See [how to report errors in PHP](https://phpdelusions.net/articles/error_reporting) – Your Common Sense Oct 25 '20 at 12:04
  • @YourCommonSense Then someone should update the official docs: https://www.php.net/manual/en/mysqli.error.php – icecub Oct 25 '20 at 12:12
  • @icecub no doubts, someone should... – Your Common Sense Oct 25 '20 at 12:15

0 Answers0