PHP bind_result not binding all variables

66 views Asked by At

I have no idea whats going on so here's the code

$q = "SELECT user_name, pass_word, email, id, auth_level FROM `userdata` WHERE user_name=?";

if ( $stmt = $db->prepare($q) ) {
    $stmt->bind_param("s", $username);
    $stmt->bind_result($result_username, $hash, $result_email, $userid, $result_auth);
    $stmt->execute();
    $stmt->store_result();

    if ( $stmt->num_rows > 0 ) {
        while ( $stmt->fetch() ) {
            if ( password_verify($password, $hash) ) {
                $_SESSION['is_user_logged_in'] = true;
                $_SESSION['user_name'] = $result_username;
                $_SESSION['user_email'] = $result_email;
                $_SESSION['user_auth_level'] = $result_auth;
                $_SESSION['user_id'] = $userid;
            }
    }
}

If i echo $userid i get blank but i should get "1", if i run this exact same query directly from phpmyadmin i get "1". anyone has any ideas?

All the other variables are being set and i can echo them

1

There are 1 answers

0
fiction On

So I just changed the data type from INT to VARCHAR and it works. Apparently bind_result doesn't like integers?