dongyan1548 2018-12-08 21:41
浏览 81

SQL查询未正确执行

There seems to be an error with my SQL query. I keep getting this warning:

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

which I'm pretty sure points to a syntax error, I found an SQL checker online and it said there's an error as well. I've been looking over this for days and I just can't seem to find what's wrong.

Here's the code:

    function countReplies($cid, $scid, $tid, $mysqli){
        $select = mysqli_query($mysqli, "SELECT category_id, subcatgory_id, topic_id FROM replies WHERE ".$cid." = category_id AND ".$scid." = subcategory_id AND ".$tid." = topic_id");

        return mysqli_num_rows($select);
   }

EDIT:

After using

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

This is the error I'm getting now:

Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''12' at line 6 in C:\xampp\htdocs(A)Book 2.0\Bootstrap\content_function.php:116 Stack trace: #0 C:\xampp\htdocs(A)Book 2.0\Bootstrap\content_function.php(116): mysqli_query(Object(mysqli), 'SELECT category...') #1 C:\xampp\htdocs(A)Book 2.0\Bootstrapeadtopic.php(55): countReplies('1', '2', '12', Object(mysqli)) #2 {main} thrown in C:\xampp\htdocs(A)Book 2.0\Bootstrap\content_function.php on line 116

  • 写回答

2条回答 默认 最新

  • douqiaosu0280 2018-12-08 21:47
    关注

    i think you should be doing the ids / actual values you put inside of the query after the '=' sign. Like:

    "SELECT category_id, subcatgory_id, topic_id FROM replies WHERE category_id = '.$cid.' 
     AND subcategory_id = '.$scid.' AND topic_id = '.$tid.';");
    
    评论

报告相同问题?

悬赏问题

  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来