致命错误导致没有结果出现(Mysqli) [英] fatal error is causing no results to appear (Mysqli)

查看:92
本文介绍了致命错误导致没有结果出现(Mysqli)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本中出现此错误,我认为这会导致搜索栏无法正常工作

I am getting this error in my script which I think is causing the search bar not to work:

致命错误:在第89行上的/web/stud/xxx/Mobile_app/previousquestions.php中的非对象上调用成员函数bind_param().

Fatal error: Call to a member function bind_param() on a non-object in /web/stud/xxx/Mobile_app/previousquestions.php on line 89.

它指向的行是这一行:

$stmt->bind_param("s",$each);    

要解决此错误需要做什么?目前,该错误导致用户在搜索栏中提交内容后未显示任何结果.

What needs to be done in order to fix this error? At the moment the error is causing no results to appear after the user has submitted the content within the search bar.

  <?php

        //connect to db

          $questioncontent = (isset($_POST['questioncontent'])) ? $_POST['questioncontent'] : '';

        ?>

        <?php 

        if (isset($_GET['searchQuestion'])) {

        $searchquestion = $questioncontent;
        $terms = explode(" ", $searchquestion);
$parameters = array();

        $questionquery = "
        SELECT q.QuestionId, q.QuestionContent, o.OptionType, q.NoofAnswers, GROUP_CONCAT(an.Answer ORDER BY an.Answer SEPARATOR ' ') AS Answer, r.ReplyType, 
               q.QuestionMarks 
          FROM Answer an 
          INNER JOIN Question q ON q.AnswerId = an.AnswerId
          JOIN Reply r ON q.ReplyId = r.ReplyId 
          JOIN Option_Table o ON q.OptionId = o.OptionId 

                         WHERE ";

        $i=0;
        foreach ($terms as $each) {     
            $i++;         

            if ($i == 1){         
                $questionquery .= "q.QuestionContent LIKE ?";     
                } else {         
                    $questionquery .= "OR q.QuestionContent LIKE ?";    
                     } 
                     }  

                     $questionquery .= "GROUP BY q.QuestionId, q.SessionId ORDER BY "; $i = 0; foreach ($terms as $each) {     
                         $i++;      

            if ($i != 1)         
            $questionquery .= "+";     
            $questionquery .= "IF(q.QuestionContent LIKE ?,1,0)"; 
            } 

            $questionquery .= " DESC "; 

            $stmt=$mysqli->prepare($questionquery);      
    $parameters[] = ($each)   
    $stmt->execute($parameters);  
            $stmt->bind_result($dbQuestionId,$dbQuestionContent,$dbOptionType,$dbNoofAnswers,$dbAnswer,$dbReplyType,$dbQuestionMarks); 
            $questionnum = $stmt->num_rows();

        }

    ?>

推荐答案

这意味着$ stmt变量的设置不正确-我认为在连接LIKE ?行后需要空格>之后.

It means that the $stmt variable isn't being set properly - I think you need spaces after the LIKE ? lines, as you're concatening GROUP BY right after it.

您需要检查所生成的SQL语句是否正确,并且数据库连接也正常工作.

You need to check that the SQL statement you're generating is correct, and that the database connection is also working.

这篇关于致命错误导致没有结果出现(Mysqli)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆