致命错误导致没有结果出现(Mysqli)

时间:2012-06-19 17:25:10

标签: php mysqli

我在我的脚本中收到此错误,我认为这会导致搜索栏无效:

  

致命错误:在第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();

        }

    ?>

1 个答案:

答案 0 :(得分:2)

这意味着$ stmt变量未正确设置 - 我认为您需要在LIKE ?行之后添加空格,因为您在它之后正在连接GROUP BY

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