1
votes

I am getting this error and I don't know what to do:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Welcome::$db
Filename: core/Model.php
Line Number: 52
Fatal error: Call to a member function insert() on null in C:\xampp\htdocs\site\application\models\account_model.php on line 38

Controller:

public function register()//function register in the controller
{
        $this->load->model('account_model');
        $this->account_model->create_account(); 
}

Model:

function create_account()//function insert.
{
    $insertdata = array('id' =>'',
        'firstname' => $this->input->post('fname'),
        'username' => $this->input->post('email'),
        'username' => $this->input->post('username'),
        'password' => $this->input->post('pass'),
        'role' => '1',
        'status' => 'Active');

    $insert = $this->db->insert('account', $insertdata);
    return $insert; 
}
2

2 Answers

1
votes

You need to load the database library into your autoload configuration file, have you already done that?

It is located in ../application/config/autoload.php, search for:

$autoload['libraries'] = array();

and add the database library like this:

$autoload['libraries'] = array('database');
0
votes

In config/autoload.php, load database library

$autoload['libraries'] = array('database');