Welcome Guest, Not a member yet? Register   Sign In
Login Form. Using a MVC pattern. Help.
#1

[eluser]theif_of_always[/eluser]
Problem: When I input a username or password. Nothing really happens. Or at least I don't think so. I keep getting same non-response or maybe I am just misdirecting it? My code is below. I am not worried about hashing it at the moment, just want to get this to work properly first. Thanks in advance!


MY CONTROLLER:
Code:
public function login() {


   if (isset( $_POST['username'] ) && isset( $_POST['password'] ))
   {

    $this->form_validation->set_rules("password", "password", "trim|required");
      $this->form_validation->set_rules("username", "username", "trim|required");
      

    
    if($this->form_validation->run() == FALSE)
    {
     $this->load->model("LoginModel");
    
    
        $isAuth = $this->LoginModel->login($_POST);
    
    
    
        if($isAuth == TRUE)
       {
      $this->session->set_userdata('user', $_POST['username']);
      redirect("dashboard/login");
      echo 'true';
        }
    
    
    else {
  
    $this->load->view("login_view");
    echo 'yeah';
    }
    
    }
  
   }
  
   else
   {
             $this->load->view("login_view");
    
   }

}
}

MY MODEL

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class LoginModel extends CI_Model {
    
    public function login($_POST)
    {
      
       $this->db->where("username", $_POST['username']);
  $this->db->where("password", $_POST['password']);
      

  $count = $this->db->count_all_results("users");        

  if ($count == 1) {
   $isAuth = TRUE;
  } else {
   $isAuth = FALSE;
  }
  
  return $isAuth;
}

}

MY VIEW

Code:
<?php
$this->load->view("header_view");
?>

      <?php echo validation_errors();?>
      <?php echo form_open('dashboard/login');?>
      
      <label for="username">Username: </label><br />
      &lt;input name='username' id="username" type='text' value='&lt;?php echo set_value('username'); ?&gt;' /&gt;&lt;br />
  
      <label for="password">Password: </label><br />
      &lt;input name='password' id="password" type='text'  value='&lt;?php echo set_value('password'); ?&gt;' /&gt;&lt;br />

      &lt;input type='submit' id="submit" value="Submit" /&gt;
  
   &lt;/form&gt;
  
&lt;?php
$this->load->view("footer_view");
?&gt;


Messages In This Thread
Login Form. Using a MVC pattern. Help. - by El Forum - 05-13-2012, 01:35 AM
Login Form. Using a MVC pattern. Help. - by El Forum - 05-13-2012, 01:53 AM
Login Form. Using a MVC pattern. Help. - by El Forum - 05-13-2012, 02:14 AM
Login Form. Using a MVC pattern. Help. - by El Forum - 05-13-2012, 02:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB