data pass through session - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: data pass through session (/showthread.php?tid=33336) |
data pass through session - El Forum - 08-23-2010 [eluser]shahmy[/eluser] i have table call student, the main fields of the student table is stu_id,f_name,L_name,....,username,password. To login to the site, I am using this student table username and password fields. I want to know, how to retrieve stu_id from the table considering username and password. Please Help me. data pass through session - El Forum - 08-23-2010 [eluser]zreedeecom[/eluser] I'm not quite sure what are you doing in your model Function but.. here is a hint: Code: function get_user_id(){ Note: Try to use more generic names for your tables and rows like "USERS", "USER_ID" etc.. it's easier to remember data pass through session - El Forum - 08-25-2010 [eluser]shahmy[/eluser] Thanks zreedeecom, for your replay, I was tried what u post above. It's OK. But I want to know how to get user_id in a session, after that i want to insert that id to another table. Please Help Me. Thank You. data pass through session - El Forum - 08-25-2010 [eluser]zreedeecom[/eluser] Take a look at: User guide > Database Library > Query Results Code: function get_user_id(){ data pass through session - El Forum - 08-26-2010 [eluser]shahmy[/eluser] zreedeecom, I do what you post, but i cant pass id form model to my controller, I copy my code with this post, please help me, "model" function validate() { $this->load->database(); $this->db->where('username', $this->input->post('username')); $this->db->where('password', md5($this->input->post('password'))); $query = $this->db->get('teacher'); if($query->num_rows > 0) { $row = $query->row(); return $row->tech_id; } //return true; } "controller" function validate_users($tech_id) { $this->form_validation->set_rules('username', 'Username', 'required'); $this->form_validation->set_rules('password', 'Password', 'required'); if ($this->form_validation->run() == FALSE) { $this->index(); } else { $this->load->model('teachers_model'); $query = $this->teachers_model->validate(); if($query) // if the user's credentials validated... { $data = array( 'tech_id'=>$tech_id, 'username' => $this->input->post('username'), 'is_logged_in' => true ); $this->session->set_userdata($data); redirect('main/teachers/memberarea'); } } } Thank You. data pass through session - El Forum - 08-26-2010 [eluser]zreedeecom[/eluser] Ok.. I've cleaned a bit your code, please read it carefully and change the things you need to make it work with the rest of your code. I've also uploaded the file with the code. Code: <?php data pass through session - El Forum - 08-27-2010 [eluser]shahmy[/eluser] Thanks zreedeecom, It is now working In good way. Thank You. data pass through session - El Forum - 08-28-2010 [eluser]zreedeecom[/eluser] [quote author="shahmy" date="1282990790"]Thanks zreedeecom, It is now working In good way. Thank You.[/quote] You are welcome :lol: |