douduan6731 2015-04-08 18:25 采纳率: 0%
浏览 6
已采纳

PHP数据库查询结果错误

Well, basically here is the error:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given in

Here is my code:

function user_banned ($con, $username) {
    $result = mysqli_query($con, "SELECT `banned` FROM `users` WHERE `username` = '$username'");
    return(mysqli_num_rows($con) == 1) ? true : false;
}

I am not too sure what is causing this, I have seen several questions about this issue, however none of them have assisted my in finding a way to fix this issue.

  • 写回答

5条回答 默认 最新

  • du656637962 2015-04-08 18:37
    关注

    You should add an extra column to your where clause: AND banned='yes' as an example.

    Plus, you're using the wrong variable in

    return(mysqli_num_rows($con) == 1) ? true : false;
    

    you need to use the query variable and not the connection

    return(mysqli_num_rows($result) == 1) ? true : false;
    

    which explains the initial error:

    Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given in...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看