php - Fatal error: Call to a member function where() on a non-object in -


i've been debugging code still not successful. can me out please?

class membership_model extends ci_model {  function __construct() {     parent::__construct(); }  function validate() {     $this->db->where('username', $this->input->post('username'));     $this->db->where('password', md5($this->input->post('password')));     $query = $this->db->get('membership');      if($query->num_rows == 1)     {         return true;     } }  function create_member() {      $new_member_insert_data = array(         'first_name' => $this->input->post('first_name'),         'last_name' => $this->input->post('last_name'),         'email_address' => $this->input->post('email_address'),                  'username' => $this->input->post('username'),         'password' => md5($this->input->post('password'))                            );      $insert = $this->db->insert('membership', $new_member_insert_data);     return $insert; } } 

i kept on getting fatal error on line

$this->db->where('username',$this->input->post('username'));

this controller/login.php

class login extends ci_controller {  function __construct() {     parent::__construct(); }  function index() {     $this->load->helper('url');     $data['main_content'] = 'login_form';     $this->load->view('includes/template', $data);       }  function validate_credentials() {            $this->load->model('membership_model');     $query = $this->membership_model->validate();      if($query) // if user's credentials validated...     {         $data = array(             'username' => $this->input->post('username'),             'is_logged_in' => true         );         $this->session->set_userdata($data);         redirect('site/members_area');     }     else // incorrect username or password     {         $this->index();     } }     function signup() {     $data['main_content'] = 'signup_form';     $this->load->view('includes/template', $data); }  function create_member() {     $this->load->library('form_validation');      // field name, error message, validation rules     $this->form_validation->set_rules('first_name', 'name', 'trim|required');     $this->form_validation->set_rules('last_name', 'last name', 'trim|required');     $this->form_validation->set_rules('email_address', 'email address', 'trim|required|valid_email');     $this->form_validation->set_rules('username', 'username', 'trim|required|min_length[4]');     $this->form_validation->set_rules('password', 'password', 'trim|required|min_length[4]|max_length[32]');     $this->form_validation->set_rules('password2', 'password confirmation', 'trim|required|matches[password]');       if($this->form_validation->run() == false)     {         $this->load->view('signup_form');     }      else     {                    $this->load->model('membership_model');          if($query = $this->membership_model->create_member())         {             $data['main_content'] = 'signup_successful';             $this->load->view('includes/template', $data);         }         else         {             $this->load->view('signup_form');                    }     }  }  function logout() {     $this->session->sess_destroy();     $this->index(); } 

the database not being initialized before validate called.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -