Error Help: Warning: mysql_num_rows() expects parameter 1 to be resource

你离开我真会死。 提交于 2019-12-11 04:54:04

问题


I'm building a simple PHP CRUD app and I'm running into this error:

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>";  
}
?>

The error points to the 34th line in that code. Any help would be greatly appreciated!


回答1:


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());


来源:https://stackoverflow.com/questions/10273244/error-help-warning-mysql-num-rows-expects-parameter-1-to-be-resource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!