Number of bind variables doesn't match number of fields...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

Number of bind variables doesn't match number of fields...

Post by aneuryzma »

Hi, I get the following error message:
Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement in /Users/aneuryzma/Sites/login_submit.php on line 65
why ?
thanks

Code: Select all

        $db = mysqli_connect('127.0.0.1', 'root', '98898989') or die("Could not connect: " . mysqli_error());
        mysqli_select_db($db, "phpro_auth");
 
        /*** prepare the select statement ***/
        //$stmt = $dbh->prepare("SELECT phpro_user_id, phpro_username, phpro_password FROM phpro_users 
        //            WHERE phpro_username = :phpro_username AND phpro_password = :phpro_password");
                    
        $sql = "SELECT phpro_user_id, phpro_username, phpro_password FROM phpro_users WHERE phpro_username = ? AND phpro_password = ?";
        
        $stmt = $db->stmt_init( );
        
        if ($stmt->prepare($sql)) {
 
            // Associate placeholders with data type and variable name
            $stmt->bind_param('ss', $phpro_username, $phpro_password);
 
            // Bind result variables
            $stmt->bind_result($user_id);
 
            // Execute prepared statement
            $stmt->execute( );
 
Last edited by Benjamin on Tue May 05, 2009 1:18 pm, edited 1 time in total.
Reason: Changed code type from text to php.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Number of bind variables doesn't match number of fields...

Post by Mark Baker »

Code: Select all

 
SELECT phpro_user_id, phpro_username, phpro_password 
 
is returning 3 (three) fields from the database

Code: Select all

 
$stmt->bind_result($user_id);
 
is binding 1 (one) returned value from the query
Post Reply