this views : alumni/loginalumni.php
<form action="<?=site_url('controller_alumni/login/submit')?>" method="post"> username: <input type="text" name="username"/> password: <input type="password" name="pass"/> <input type="submit" /></form>
this controller : controller_alumni.php
public function login($submit = null){ if($submit==null){ $this->load->view('alumni/login_alumni'); return true; } $username= $this->input->post('username'); $pass= $this->input->post('pass'); $this->load->model('model_alumni'); $result = $this->model_alumni->login($username, $pass); if($result==true){ echo 'login'; } else{ echo 'login failed'; } }
and model: model_alumni.php
public function login($username, $pass){ $query = $this->db->get_where('tb_alumni',[ 'username' => $username, 'pass' => sha1($pass . hash_key) ]); return $query->result(); }
when run, , insert username , password , : "login failed"
please change
public function login($submit = null){ if($submit==null){ $this->load->view('alumni/login_alumni'); return true; } $username= $this->input->post('username'); $pass= $this->input->post('pass'); $this->load->model('model_alumni'); $result = $this->model_alumni->login($username, $pass); if($result==true){ echo 'login'; } else{ echo 'login failed'; } }
to
public function login($submit = null){ if($submit==null){ $this->load->view('alumni/login_alumni'); return true; } $username= $this->input->post('username'); $pass= $this->input->post('pass'); $this->load->model('model_alumni'); $result = $this->model_alumni->login($username, $pass); if(!empty($result)){ echo 'login'; } else{ echo 'login failed'; } }
because if user name , password correct it's return data not true , $result data . please check empty()
Comments
Post a Comment