Jump to content

MySQLi insert failing when trying to add remember me functionality


programming2music

Recommended Posts

I am trying to make a login which works perfectly until I try and add remember me functionality into the User class. 

 



    if ( $user ) {
            // check login password agaisnt the hash
            if (Hash::verify($password, $this->data()['password'])) {
                Session::put($this->_sessionName, $this->data()['id']);
 
                if ($remember) {
                   $this->mysqli->insert('user_session', array(
                       'user_id' => $this->data()['id'],
                       'hash'    => uniqid(),
                   ));
                }
           }
            return true;
        }
        return false;    
 


I am getting the error.

 

   

mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables    


 

But when I echo out the query out I have the correct number of elements.

 

 

SELECT * FROM users WHERE id= ?SELECT * FROM users WHERE id= ?INSERT INTO user_session ( `user_id`, `hash`) VALUES (?, ?)


 

Does anyone have any idea? I think someone the other queries are affecting it somehow but i'm not sure how.
Edited by programming2music
Link to comment
Share on other sites

 

 

But when I echo out the query out I have the correct number of elements.

 

SELECT * FROM users WHERE id= ?SELECT * FROM users WHERE id= ?INSERT INTO user_session ( `user_id`, `hash`) VALUES (?, ?)

Is that the actual query your code is trying to execute? There appears to be three queries within in one query there.

Link to comment
Share on other sites

Thanks for the reply. I am new to PHP and followed a tutorial on building a class using MySQLi and was echoing the query from this method.

protected function _prepareQuery()
    {
        echo $this->_query;
        if (!$stmt = $this->_mysql->prepare($this->_query)) {
            var_dump($this->_mysql->error);
        }
        return $stmt;
    }

I am executing one statement at a time, just looks like 3 in one line from how i was echoing.

Edited by programming2music
Link to comment
Share on other sites

I posted the whole code because in the class he breaks parts up into separate methods.

 

http://pastebin.com/vF6eiK9Y

 

There isn't a problem with the insert in this class as I use it to create new accounts, I think the problem might be somewhere either in the validation or the user class, I heard something about freeing results but i'm not sure how to go about that.

 

Thanks for the help

Link to comment
Share on other sites

the database class you found is more of the nonsense code that gets published on the web. it contains no initialization logic, so using it for more than one query in a row will mix property values together, which is probably what's causing the current error (the bind_param() parameter type string contains the type values from the previous query and the current query.)

 

i recommend you write your own code, so that you learn and gain in your own experience, rather than to try and use bits of code posted on the web.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.