1

controllers/verify_login.php page

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

class Verify_login extends CI_Controller {

 function __construct()
 {
   parent::__construct();
   $this->load->model('adminl_model') ;
 }

 function index()
 {
   //This method will have the credentials validation
   $this->load->library('form_validation');

   $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
   $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');

   if($this->form_validation->run() == FALSE)
   {
     //Field validation failed.  User redirected to login page
     $this->load->view('admin/index');
   }
   else
   {
     //Go to private area
     redirect('about', 'refresh');
   }

 }

 function check_database($password)
 {
   //Field validation succeeded.  Validate against database
   $username = $this->input->post('username');

   //query the database

   $result = $this->Admin_Model->login($username, $password);

   if($result)
   {
     $sess_array = array();
     foreach($result as $row)
     {
       $sess_array = array(
         'id' => $row->id,
         'username' => $row->username
       );
       $this->session->set_userdata('logged_in', $sess_array);
     }
     return TRUE;
   }
   else
   {
     $this->form_validation->set_message('check_database', 'Invalid username or password');
     return false;
   }
 }
}

models/adminl_model.php page

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
Class Adminl_Model extends CI_Model
{
     function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
 function login($username, $password)
 {
   $this -> db -> select('id, username, password','type');
   $this -> db -> from('users');
   $this -> db -> where('nick', $username);
   $this -> db -> where('type', 'admin');
   $this -> db -> where('pass', MD5($password));
   $this -> db -> limit(1);

   $query = $this -> db -> get();

   if($query -> num_rows() == 1)
   {
     return $query->result();
   }
   else
   {
     return false;
   }
 }

}

Gives error. How can I fix that ? I am working on c9.io. and stackoverflow saying that is so codely. I understood my problem that is ridiculous.

6
  • what error are you getting? Commented Sep 28, 2014 at 7:58
  • $this->load->model('adminl_model') or die("error"); so just error text Commented Sep 28, 2014 at 8:03
  • and php gives ; A PHP Error was encountered Severity: Notice Message: Undefined property: Verify_login::$Admin_Model Filename: controllers/verify_login.php Line Number: 40 Commented Sep 28, 2014 at 8:06
  • not an answer to the question, but if you have "limit(1)" on the query "$query -> num_rows() == 1" is not needed. Commented Sep 28, 2014 at 8:09
  • pls provide verify_login controller code Commented Sep 28, 2014 at 8:10

2 Answers 2

1

This chunk of code :

$result = $this->Admin_Model->login($username, $password);

Must be:

$result = $this->adminl_model->login($username, $password);
Sign up to request clarification or add additional context in comments.

Comments

1

use $this->admin_model->login($username, $password); instead of $this->Admin_Model->login($username, $password);

Once loaded, you will access your model functions using an object with the same name as your class:

here you have loaded the model as $this->load->model('adminl_model') ;, so u can use adminl_model instead of Admin_Model

2 Comments

i did it and i said what php says and i added codes of verify_login
@Nurullah Macun , modified my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.