dsgwii4867 2014-02-02 21:07
浏览 60

警告:mysql_num_rows()期望参数1是资源,布尔值是? [重复]

I'm trying to make a log in system using PHP but when I purposely attempt to log in with incorrect credentials this error message appears:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in ...

The message I want to echo when someone types in the wrong credentials appears, but it appears below the warning message. These are the lines of code associated with the line of code causing the warning message to appear:

$query = mysql_query("SELECT * FROM users WHERE username='$user'");
if ($numrows == 1){
$row = mysql_fetch_assoc($query);
$dbid = $row['id'];
$dbuser = $row['username'];
$dbpass = $row['password'];
$dbactive = $row['active'];

And here is the actual line of code itself:

$numrows = mysql_num_rows($query);

I may need to edit the question to add more lines of code, please tell me if I do. Also this question may be a possible duplicate of this post: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in but I'm not too sure though. But please tell me what could be causing this warning message to appear.

</div>
  • 写回答

1条回答 默认 最新

  • dongmacheng3222 2014-02-02 21:10
    关注

    If mysql_query returns false, this is boolean, so you need to check it first before passing it on to mysql_num_rows

    $query = mysql_query("SELECT * FROM users WHERE username='$user'");
    
    if($query)
      $numrows = mysql_num_rows($query);
    else
      die("something failed");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 vue3+element-plus页面崩溃
  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理