This is my code. can anyone try to figure out why is there an error.
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "fruitsandvegetables";
$conn = new mysqli($servername, $username, $password, $dbname);
if($conn->connect_error) {
die ("connection failed: " . $conn->connect_error);
}
$sql = "SELECT productID,productName,productPricePerKg,productStockKg,FROM fruitsandvegetables";
$result = $conn->query($sql);
echo "<table style='width: 100%'>";
echo "<tr>";
echo"<th> productID</th>";
echo "<th>productName</th>";
echo "<th> productPricePerKg</th>";
echo "<th> productStockKg</th>";
echo "</tr>";
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td> {$row["productID"]}</td>";
echo"<td> {$row["productName"]}</td>";
echo "<td>{$row["productPricePerKg"]}</td>";
echo "<td>{$row["productStockKg"]}</td>";
echo"</tr>";
}
} else {
echo "0 results";
}
echo "</table>";
$conn->close();
error on if($result->num_rows > 0){
trying to get property of non object
can anyone figure out why? thank you. the front end is php and the backend is sql