CodeIgniter Forums
New to Codeigniter Error issue with Login and Register code - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: New to Codeigniter Error issue with Login and Register code (/thread-64777.html)



New to Codeigniter Error issue with Login and Register code - ossieboy - 03-25-2016

Hi

Very new to Codeigniter 

when using the Login and Register Video part 6 I keep coming up with this error, when xss_clean is taken out of the code as advised.

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Main::$db
Filename: core/Model.php
Line Number: 77
Backtrace:
File: C:\wamp\www\ci_user\application\models\model_users.php
Line: 7
Function: __get
File: C:\wamp\www\ci_user\application\controllers\main.php
Line: 37
Function: can_log_in
File: C:\wamp\www\ci_user\application\controllers\main.php
Line: 27
Function: run
File: C:\wamp\www\ci_user\index.php
Line: 292
Function: require_once


Fatal error: Call to a member function where() on a non-object in C:\wamp\www\ci_user\application\models\model_users.php on line 7
A PHP Error was encountered
Severity: Error
Message: Call to a member function where() on a non-object
Filename: models/model_users.php
Line Number: 7
Backtrace:
 

Any help would be appreciated


RE: New to Codeigniter Error issue with Login and Register code - pravins - 03-25-2016

Can you please post the code


RE: New to Codeigniter Error issue with Login and Register code - Rhyno_xD - 03-25-2016

did you extend CI_Model class also post the code here.


RE: New to Codeigniter Error issue with Login and Register code - ossieboy - 03-25-2016

(03-25-2016, 09:45 AM)Rhyno_xD Wrote: did you extend CI_Model class also post the code here.

class model_users extends CI_Model{


public function __construct() 
     
           parent::__construct(); 
           $this->load->database();

public function can_log_in(){

$this->db->where('email',$this->input->post('email'));
$this->db->where('password',md5($this->input->post('password')));
$query = $this->db->get('user');

if ($query->num_rows()== 1){

return true;

}else{
return false;
}
}
}


RE: New to Codeigniter Error issue with Login and Register code - ossieboy - 03-28-2016

(03-25-2016, 11:00 AM)ossieboy Wrote:
(03-25-2016, 09:45 AM)Rhyno_xD Wrote: did you extend CI_Model class also post the code here.

class model_users extends CI_Model{


public function __construct() 
     
           parent::__construct(); 
           $this->load->database();

public function can_log_in(){

$this->db->where('email',$this->input->post('email'));
$this->db->where('password',md5($this->input->post('password')));
$query = $this->db->get('user');

if ($query->num_rows()== 1){

return true;

}else{
return false;
}
}
}


Yes I did extend the CI 
The problem seems to be in the file below with the callback function :

Maiin.php

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


class Main extends CI_Controller {


public function index(){
$this->login();
}

public function login(){ 
$this->load->view('login');
}

public function members(){
$this->load->view('members');

}

public function login_validation(){

$this->load->library('form_validation');

$this->form_validation->set_rules('email', 'Email','required|trim|callback_validate_credentials'); 
$this->form_validation->set_rules('password', 'Password','required|trim');  



if ($this->form_validation->run()){
redirect('main/members');
}else{
$this->load->view('login');
}
}

public function validate_credentials (){
$this->load->model('model_users');

if ($this->model_users->can_log_in()){
return true;


}else{

$this->form_validation->set_message('validate_credentials','incorrect username/password.');

return false;
}


}

}




RE: New to Codeigniter Error issue with Login and Register code - ciadmin - 03-29-2016

It sounds like your database driver is not being loaded ... $this->load->library('database'); or autoload it.
Further, your class name may work on WIndows, but you will have issues with the non-UCfirst name if you deploy to a Linux server; the class name should be Model_users.


RE: New to Codeigniter Error issue with Login and Register code - ossieboy - 03-29-2016

(03-29-2016, 12:29 AM)ciadmin Wrote: It sounds like your database driver is not being loaded  ... $this->load->library('database'); or autoload it.
Further, your class name may work on WIndows, but you will have issues with the non-UCfirst name if you deploy to a Linux server; the class name should be Model_users.

Thanks for your help the problem was in $autoload['libraries'] = array('database', 'email', 'session');
the array was not loaded with information.
Now working fine  thanks

I bet us newbies keep you busy with crazy questions??