如何解决警告:mysqli_num_rows()要求参数1为mysqli_result,第51行的C:\ xampp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ [英] How to fix warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\view.php on line 51
问题描述
您好我之前提到过的问题我是PHP初学者,我必须设计一个可以查看数据库,添加和删除数据库记录的网站。
我一直收到以下错误:
警告:mysqli_num_rows()要求参数1为mysqli_result,布尔值在C:\ xampp \ htdocs中给出第51行\ View.php
以下是查看数据库的代码(View.PHP):
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
/*
View.PHP
Displays all data from 'productorders' table
*/
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "stationaryonlinecustomers";
// connect to database
$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>
为什么会发生这种情况并且是修复此错误的解决方案?
如果有人可以帮助我,我会非常感激。
我尝试了什么:
已经关注youtube,PHP指南,网站和书籍上的在线视频教程。
我咨询了同事,但无法帮助删除此错误。
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.
推荐答案
servername =localhost;
servername = "localhost";
username =root;
username = "root";
密码=;
这篇关于如何解决警告:mysqli_num_rows()要求参数1为mysqli_result,第51行的C:\ xampp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!