php - codeigniter login form is not displaying is i post -


this users controller

function login(){  $data['error']=0; if($_post){         $this->load->model('user');         $username=$this->input->post('username', true);         $password=$this->input->post('password', true);          $type=$this->input->post('user_type', true);         $user=$this->user->login($username,$password,$type);         if(!$user){             $data['error']=1;                   } else {             $this->session->set_userdata('userid', $user['userid']);             $this->session->set_userdata('user_type', $user['user_type']);             redirect(base_url(). 'posts');                         }         $this->load->view('header');         $this->load->view('login',$data);         $this->load->view('footer');     }     } 

this user model

   function login($username,$password){         $where=array(             'username'=>$username,             'password'=>sha1($password),             'user_type'=>$type         );         $this->db->select()->from('users')->where($where);         $query=$this->db->get();         return $query->first_row('array'); } 

this view

<?php if($error==1){ ?> <p>your identity wrong</p> <?php } ?> <form action="<?php echo base_url()?>users/login" method="post"> <p>user name: <input type="text" name="username" /></p> <p>password: <input type="password" name="password" /></p> <p><input type="submit" value="login" /></p> </form> 

not problem on view (form view'login') not displaying if remove if($_post) user controller works there place have don mistake on controller of model or view,

my table ('username','password','email','user_type')

regards, in advance kind of tips

you loading view page inside if($_post) condition. @ first, if($_post) false, view not loading.

so, need correct it.

just use:

function login(){  $data['error']=0;          $this->load->model('user');         $username=$this->input->post('username', true);         $password=$this->input->post('password', true);     $type=$this->input->post('user_type', true);     $user=$this->user->login($username,$password,$type);     if(!$user){         $data['error']=1;               } else {         $this->session->set_userdata('userid', $user['userid']);         $this->session->set_userdata('user_type', $user['user_type']);         redirect(base_url(). 'posts');                     }     $this->load->view('header');     $this->load->view('login',$data);     $this->load->view('footer');  } 

and work perfectly.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -