错误帮助:警告:mysql_num_rows()期望参数1为资源 [英] Error Help: Warning: mysql_num_rows() expects parameter 1 to be resource
本文介绍了错误帮助:警告:mysql_num_rows()期望参数1为资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在构建一个简单的PHP CRUD应用,并且遇到了此错误:
I'm building a simple PHP CRUD app and I'm running into this error:
警告:mysql_num_rows()期望参数1为资源,布尔值输入
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in
<?php
$query = "select * from user";
$result = mysql_query($query);
if (mysql_num_rows($result) > 1) {
echo "<table align='center' border='1'>";
echo "<tr>";
echo "<th>Id</th>";
echo "<th>Username</th>";
echo "<th>Password</th>";
echo "</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['username']."</td>";
echo "<td>".$row['password']."</td>";
echo "<td><a href='index.php?operation=edit&id=".$row['id']."&username=".$row['username']."&password=".$row['password']."'>edit</a></td>";
echo "<td><a href='index.php?operation=delete&id=".$row['id']."'>delete</a></td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "<center>No Records Found!</center>";
}
?>
错误指向该代码中的第34行.任何帮助将不胜感激!
The error points to the 34th line in that code. Any help would be greatly appreciated!
推荐答案
通常,这意味着由于字段名不正确等导致查询失败-您确定表存在吗?尝试使用一些错误处理来弄清问题所在.
Usually this means your query failed due to incorrect fieldnames etc - are you sure your table exists? Try using some error handling to give an idea what the issue is.
$result = mysql_query($query) or die('Cannot Execute:'. mysql_error());
这篇关于错误帮助:警告:mysql_num_rows()期望参数1为资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文