php - Creating the Users MVC codeigniter tuts tutorial -


hi im having problems users tutorial on tuts... when type username , password in login form comes not validated. im not sure whats going on. here's code

model: user.php

    <?php      class user extends ci_model     {              // create user     function create_user($data){         $this->db->insert('users',$data);     }      // login     function login($username,$password){         $where=array(             'username'=>$username,             'password'=>$password);         $this->db->select()->from('users')->where($where);         $query=$this->db->get();         return $query->first_row('array');     } } 

controller: users.php

    <?php  class users extends ci_controller {          // login function     function login(){         $data['error']=0;         if ($_post){             $this->load->model('user');             $username=$this->input->post('username',true);             $password=$this->input->post('password',true);             $user=$this->user->login($username,$password);             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().'index.php/posts/');             }         }         $this->template->load('layout/template', 'login', $data);      }      // logout function     function logout(){         $this->session->sess_destroy();         redirect (base_url()).'index.php/posts/';     }  } 

view: login.php

<h2>login</h2> <div class="row">     <div class="span12">     <?php if($error==1){ ?>     <p class="alert alert-error ">             username/password did not match...     </p>     <?php } ?>      <p>          <form action="<?=base_url()?>index.php/users/login" method="post">         <p><input class="span3" name="username" type="text" placeholder="username"></p>         <p><input class="span3" name="password" type="password" placeholder="password"></p>          <p><button class="btn btn-primary" type="submit">login</button></p>         </form>      </p>     </div> </div> 

ive gone through thoroughly cannot find anything...

any or info grateful please gentle im newbie lol...

chris

for controller;

try line

if( count($_post[]) > 0 ) { 

or

if( $this->input->server('request_method') === 'post' ) { 

instead of line

if ($_post){ 

for model;

// login function login($username,$password){     $where=array(         'username'=>$username,         'password'=>$password);     $query = $this->db->get_where('users',$where);     return $query->first_row('array'); } 

just in case, never store passwords without encrypt them!


Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -