Userdata and session data into database |
[eluser]someone [/eluser]
Hello, How can I get some data from userdata, to show it on site? I'm trying to store it in userdata with set_userdata() from database, but I always get error "Object of class stdClass could not be converted to string". Controller: Code: $checklogin = $this->Userdat->check_login($this->input->post('username', TRUE), crypt($this->input->post('password', TRUE), 'somehash')); Model: Code: public function checklogin($username, $password) And then if I want to show some data (just for testing) in controller I use: $this->userdata('username'); but there is problem with error which I mentioned before. Second question is about storing session data into database. Is this good and can I change name of table and fields into my language? How to use this data then and when I can delete it or how to delete it if it's old? Thanks in advance! :-)
[eluser]CroNiX[/eluser]
$this->userdata(‘username’); You're not accessing the session class here...
[eluser]someone [/eluser]
[quote author="CroNiX" date="1342459942"]$this->userdata(‘username’); You're not accessing the session class here...[/quote] Then I get this error: "Fatal error: Call to undefined method User::userdata()". But if I leave $this->session->userdata(‘username’); in other function in this controller, then it works normally. Error is only when I want to display data from userdata() or compare it to some string or int. Where am I doing mistake?
[eluser]InsiteFX[/eluser]
Code: $this->session->set_userdata(array(
[eluser]someone [/eluser]
It also doesn't work, but I changed code a little bit, because I didn't get errors. This is new (only for testing) code: Code: $checklogin = $this->Userdat->check_login($this->input->post('username', TRUE), crypt($this->input->post('password', TRUE), 'somehash')); After I log in, I get this error "Object of class stdClass could not be converted to string", same as before. In the case if I change to 'username' => $checklogin->username, I get this error: "Undefined property: CI_DB_mysql_result::$username". Where is the problem?
[eluser]someone [/eluser]
I found a problem... Instead of Code: $checklogin = $this->db->select('id_user', 'username')->where(array('username' => $username, 'password' => $password))->get('users'); Code: $checklogin = $this->db->select('id_user, username')->where(array('username' => $username, 'password' => $password))->get('users'); Thanks for help anyway! :-)
[eluser]InsiteFX[/eluser]
It's because of the type your returning from your database query. Code: $checklogin = $this->Userdat->check_login($this->input->post('username', TRUE), crypt($this->input->post('password', TRUE), 'somehash'))->result_array(); CodeIgniter Users Guide - Generating Query Results |
Welcome Guest, Not a member yet? Register Sign In |