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
$query = "select * from user";
$result = mysql_query($query);
if (mysql_num_rows($result) > 1) {
echo "
echo "
";echo "
Id";echo "
Username";echo "
Password";echo "
";while($row = mysql_fetch_array($result)) {
echo "
";echo "
".$row['id']."";echo "
".$row['username']."";echo "
".$row['password']."";echo "
edit";echo "
delete";echo "
";}
echo "
";} else {
echo "
}
?>
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());