I am currently building a web for student registration and I am using CodeIgniter. I already managed to insert the form to my database and I am using email and password from the submitted form to login. I got a problem in my login page,somehow it cant check either the email or password exists on the database or not and it cant redirect to my desired page either.
This is my controller
public function index()
{
$data = '';
if($this->input->post('submit'))
{
$this->form_validation->set_rules('email','email','required');
$this->form_validation->set_rules('password','password','md5|required');
if($this->form_validation->run())
{
$email = $this->input->post('email');
$password = md5($this->input->post('password'));
$this->load->model('testmodel','user');
$member = $this->user->selectUser("WHERE email = '$email' AND password = '$password'");
if($member->has_rows())
{
$user_data = array(
'name' => $member->row('name'),
'nisn' => $member->row('nisn'),
'email' => $member->row('email'),
'logged_in_admin' => TRUE
);
$this->session->set_userdata($user_data); redirect('pages/userpage/userpage');
}else
{
$data['message'] = '<div class = "error">Username and password wrong!</div>';
}
}else
{
$data['message'] = '<div class = "error">' . validation_errors() . '</div>';
}
}
$this->load->view('pages/userlogin/userlogin',$data);
}
This is the selectuser function in testmodel
public function selectUser($where = '', $sort = 'DESC', $limit = '')
{
$query = "
SELECT SQL_CALC_FOUND_ROWS * FROM student_table
$where
ORDER BY ticketnumber $sort
$limit
";
return $this->db->query($query);
}'