The following code index.php is stored at C:\xampp\htdocs\xss\3\index.php.
When I try to run it, I'm getting this error. Please let me know how to fix this issue.
URL in my computer
- Code: Select all
http://localhost/xss/3/
Error Message
- Code: Select all
Notice: Trying to get property of non-object in C:\xampp\htdocs\xss\3\index.php on line 75
Line 75 of C:\xampp\htdocs\xss\3\index.php
- Code: Select all
if ($result->num_rows > 0) {
Related code:
- Code: Select all
<?php
$sql = "SELECT id, comment FROM comments";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td style='width:35%;padding:10px'>Comment #".$row["id"]."<br /><hr />".$row["comment"]."<br /></td></tr>";
}
} else {
echo "<tr><td style='width:35%'>No Comments!</td></tr>";
}
$conn->close();
?>
Please let me know if you need more info to resolve this issue.