Hi as i have mentioned in previous questions I am a beginner in PHP, I have to design a website which can view a database, add and delete records from the database.
I keep getting the following error:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\View.php on line 51
The following is the code for viewing the database (View.PHP):
<html>
<head>
<title>View Records</title>
</head>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "stationaryonlinecustomers";
$con = mysqli_connect("localhost","root","") or die("Error");
# get results from database
$i ="SELECT * FROM productorders";
$result = mysqli_query($con, $i);
#or die(mysql_error());
# display data in table
echo "<p>View All" ;
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>Product Name</th> <th>Price</th> <th>Stock</th> <th></th></tr>";
# loop through results of database query, displaying them in the table
echo $result;
if (mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)) {
# echo out the contents of each row into a table
echo "<tr>";
echo "<td>" . $row['ID']. "</td>";
echo "<td>" . $row['Product Name']. "</td>";
echo "<td>" . $row['Price']. "</td>";
echo "<td>" . $row['Stock']. "</td>";
echo "<td><a href='edit.php'> Edit</a></td>";
echo "<td><a href='delete.php'> Delete</a></td>";
echo "</tr>";
}
}
echo "</table>";
?>
<a href="New.php">Add a new record</a></p>
<a href="New.php">Delete a record</a></p>
</body>
</html>
Why is this happening and is the solution to fixing this error ?
If anyone can help me I would really Appreciate it.
What I have tried:
Have followed online video tutorials on youtube, PHP Guides, websites and books.
I have consulted fellow colleagues but are unable to help remove this error.