data pass through session |
[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.
[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
[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.
[eluser]zreedeecom[/eluser]
Take a look at: User guide > Database Library > Query Results Code: function get_user_id(){
[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.
[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
[eluser]shahmy[/eluser]
Thanks zreedeecom, It is now working In good way. Thank You.
[eluser]zreedeecom[/eluser]
[quote author="shahmy" date="1282990790"]Thanks zreedeecom, It is now working In good way. Thank You.[/quote] You are welcome :lol: |
Welcome Guest, Not a member yet? Register Sign In |