programming2music Posted January 16, 2015 Share Posted January 16, 2015 (edited) 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 January 16, 2015 by programming2music Quote Link to comment https://forums.phpfreaks.com/topic/293984-mysqli-insert-failing-when-trying-to-add-remember-me-functionality/ Share on other sites More sharing options...
Ch0cu3r Posted January 16, 2015 Share Posted January 16, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/293984-mysqli-insert-failing-when-trying-to-add-remember-me-functionality/#findComment-1503146 Share on other sites More sharing options...
programming2music Posted January 16, 2015 Author Share Posted January 16, 2015 (edited) 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 January 16, 2015 by programming2music Quote Link to comment https://forums.phpfreaks.com/topic/293984-mysqli-insert-failing-when-trying-to-add-remember-me-functionality/#findComment-1503147 Share on other sites More sharing options...
Ch0cu3r Posted January 16, 2015 Share Posted January 16, 2015 Can you show the code for the insert method? Quote Link to comment https://forums.phpfreaks.com/topic/293984-mysqli-insert-failing-when-trying-to-add-remember-me-functionality/#findComment-1503156 Share on other sites More sharing options...
programming2music Posted January 16, 2015 Author Share Posted January 16, 2015 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 Quote Link to comment https://forums.phpfreaks.com/topic/293984-mysqli-insert-failing-when-trying-to-add-remember-me-functionality/#findComment-1503171 Share on other sites More sharing options...
mac_gyver Posted January 18, 2015 Share Posted January 18, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/293984-mysqli-insert-failing-when-trying-to-add-remember-me-functionality/#findComment-1503280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.