Page 1 of 1

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

Posted: Tue May 05, 2009 10:32 am
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( );
 

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

Posted: Tue May 05, 2009 11:38 am
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