简体   繁体   English

mysql_num_rows PHP

[英]mysql_num_rows PHP

elseif(isset($_POST['submit']))
{
    // Look for their user
    $lookuser = mysql_query("SELECT * FROM `users` WHERE username='". mysql_escape_string($_POST['username']) ."'");
    // If we find a row
    if(mysql_num_rows($lookuser) > 0)

But my else for that, echos: An error has occured. <br> If you are sure you entered your username correctly, please contact an administrator. 但是我对此的其他回应是: An error has occured. <br> If you are sure you entered your username correctly, please contact an administrator. An error has occured. <br> If you are sure you entered your username correctly, please contact an administrator.

I've tried to echo $_POST['username']; 我试图回显$_POST['username']; all works out fine. 一切正常。 I've made sure my user exists, that works out fine. 我已经确定我的用户存在,这很好。

The PHP error I get: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in password.php on line 23 我收到的PHP错误: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in password.php on line 23

Php.net says this about the return value of mysql_query: php.net这么说有关mysql_query的返回值:

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. 对于SELECT,SHOW,DESCRIBE,EXPLAIN和其他返回结果集的语句,mysql_query()成功时返回资源,错误时返回FALSE。

If you're getting a boolean, it's because there's a mysql error. 如果获取布尔值,这是因为存在mysql错误。 Use mysql_error() to print the error, it'll help you diagnose the issue. 使用mysql_error()打印错误,它将帮助您诊断问题。

You probably have an error in your sql query. 您的SQL查询中可能有一个错误。 To be sure of that, echo after your mysql_query mysql_error() . 为确保这一点,请在mysql_query mysql_error()之后回显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM