[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]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]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]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: