SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to remove the warning below in mysqli

    The problem I have is that it is giving me a warning in mysqli stating this:



    Warning: mysqli_stmt::bind_param() [mysqli-stmt.bind-param]: Number of variables doesn't match number of parameters in prepared statement in ...on line 89

    How can I get rid of the warning?
    PHP Code:
        $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);      
             
    $stmt->bind_param('s'$each '%' $each '%');
            
    $stmt->execute(); 
            
    $stmt->bind_result($dbQuestionId,$dbQuestionContent,$dbOptionType,$dbNoofAnswers,$dbAnswer,$dbReplyType,$dbQuestionMarks); 
            
    $questionnum $stmt->num_rows(); 
    OUTPUT OF SQL:
    Code:
        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 q.QuestionContent LIKE ? 
        
        GROUP BY q.QuestionId, q.SessionId 
        
        ORDER BY IF(q.QuestionContent LIKE ? ,1,0) DESC
    Last edited by SpacePhoenix; Jun 21, 2012 at 23:10. Reason: placed php tags around the php code

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    you posted this in the databases forum, not the php forum, so all i can ask you is whether when you ran the sql right in mysql, i.e. outside of php, did it work or not?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    San Sebastian, Spain
    Posts
    93
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi, basically any where you have a ? in your SQL you need to provide a bind variable. Even if this means duplicating something you already have. So the bind operation is expecting 2 entries and you are providing only 1. I think this should be done as follows:

    $each = '%' . $each . '%';
    $stmt->bind_param('ss', $each, $each);


Tags for this Thread

Bookmarks

Posting Permissions

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