3

我在我的脚本中收到此错误,我认为这导致搜索栏无法正常工作:

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

它指向的线是这条线:

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

需要做什么才能修复此错误?目前,该错误导致用户在搜索栏中提交内容后没有出现任何结果。

  <?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();

        }

    ?>
4

1 回答 1

2

这意味着 $stmt 变量没有被正确设置 - 我认为你需要在行后有空格LIKE ?,因为你GROUP BY在它之后连接。

您需要检查您生成的 SQL 语句是否正确,以及数据库连接是否正常。

于 2012-06-19T17:28:01.017 回答