www.webdeveloper.com
Results 1 to 5 of 5

Thread: How to fix mysqli warning and error

Threaded View

  1. #1
    Join Date
    Nov 2011
    Posts
    27

    How to fix mysqli warning and error

    I have a query which was correct in terms of the statements as this was tested in MYSQL. But when trying to switch from mysql to use mysqli, I can't seem the get the results to appear after a successful search.

    I am getting 2 errors though which are these:


    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'Array' was given in ... on line 78

    Fatal error: Call to a member function execute() on a non-object in ... on line 79

    I don't understand why I am getting the warning though because I am calling on an array so I don't know why the warning appears. I am guessing the fatal error would go i the warning goes but I am not sure.
    Code:
      <?php
            
            $username="zzz";
            $password="zzz";
            $database="mobile_app";
            
              $mysqli = new mysqli("localhost", $username, $password, $database);
            
              /* check connection */
              if (mysqli_connect_errno()) {
                printf("Connect failed: &#37;s\n", mysqli_connect_error());
                die();
            }
            
            ?>
            
        <form action="previousquestions.php" method="get">
        <p>Search: <input type="text" name="questioncontent" value="<?php echo $questioncontent; ?>" onchange="return trim(this)" /></p>
        <p><input id="searchquestion" name="searchQuestion" type="submit" value="Search" /></p>
        </form>
                
                <?php 
                
                if (isset($_GET['searchQuestion'])) {
            
                $questioncontent = (isset($_GET['questioncontent'])) ? $_GET['questioncontent'] : '';
                $searchquestion = $questioncontent;
                $terms = explode(" ", $searchquestion);
                  
                $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, 
                MATCH (q.QuestionContent) AGAINST (? IN NATURAL LANGUAGE MODE) AS score 
                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 MATCH (q.QuestionContent) AGAINST (? IN NATURAL LANGUAGE MODE) 
                GROUP BY q.QuestionId, q.SessionId 
                ORDER BY score 
                ";
                
                $paramTypes = '';
                $params = array();			 
                $i=0;
                
                //loop through each term
                foreach ($terms as $each) {
                    $i++;
                    $params[] = "%$each%";
                    $paramTypes .= "s";
                }
                 
                
                	$stmt=$mysqli->prepare($questionquery);   
        call_user_func_array(array($stmt, 'bind_param'), array_merge(array($paramTypes), $params));
                	$stmt->execute();
                	$stmt->bind_result($dbQuestionContent); 
                	$questionnum = $stmt->num_rows();
                	
                	
                  if($questionnum ==0){
                    echo "<p>Sorry, No Questions were found from this Search</p>";
                    }
                    else{
                      
                      $output = "";
                $output .= "
                    <table border='1' id='resulttbl'>
                      <tr>
                      <th class='questionth'>Question</th>
                      </tr>
                ";
                        while ($stmt->fetch()) {
                $output .= "
                      <tr>
                      <td class='questiontd'>{$dbQuestionContent['QuestionContent']}</td>
                      </tr>";
                        }
                        $output .= "        </table>";
                        
                        echo $output;
                
                  }
                  
                }
                
                ?>
    Last edited by carlbrooks; 06-25-2012 at 08:18 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles