I have built an application and am having a problem with login, which I can't identify but I believe it might come from my model when I try to log in I get unsuccessful message, I believe I can read database but don't know where the problem is
Here is my code
Controller
Code:
public function index(){
echo "<script> document.location.href='".$this->config->base_url()."index.php/admin/login' </script>";
}
public function login()
{
$this->load->helper('url');
$this->load->model('admin_model');
$this->load->database('default', TRUE);
function get_data($table, $fields, $condition,$orderby=NULL) {
$this->load->database();
$condition = (isset($condition))? ' WHERE '.$condition : '';
$orderby = (isset($orderby))? ' ORDER BY '.$orderby : '';
//if(!$condition) $condition = 'active = A';
//if(!$orderby) $orderby = 'id DESC';
$result = $this->db->query('SELECT '.$fields.' FROM '.$table.$condition.$orderby );
return $result;
}
function validate() {
$username=$this->input->post('Username');
$pass=$this->input->post('Password');
$this->load->database();
$res=$this->db->query("SELECT count(*) AS cnt,id,emp_type,employee_name, report_to FROM employee_login WHERE username='$username' AND password='".md5($pass)."'");
foreach ($res->result() as $rows){
$cnt=$rows->cnt;
$id=$rows->id;
$emp_type=$rows->emp_type;
$report_to=$rows->report_to;
$emp_name=$rows->employee_name;
}
if($cnt>0){
--
-- Table structure for table `employee_login`
--
CREATE TABLE IF NOT EXISTS `employee_login` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`employee_name` varchar(500) NOT NULL,
`username` varchar(500) NOT NULL,
`password` varchar(500) NOT NULL,
`emp_type` varchar(50) NOT NULL,
`emp_email` varchar(100) NOT NULL,
`report_to` varchar(100) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;