1

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 Answers 2

1

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');
Sign up to request clarification or add additional context in comments.

2 Comments

Big help Konstantin. However after i change it, another error appeared. Your application/config/database.php file does not appear to contain a valid configuration array.
Sorry my bad. this is the error. --- Unable to connect to your database server using the provided settings. Filename: C:\xampp\htdocs\site\system\database\DB_driver.php Line Number: 125
0

In config/autoload.php, load database library

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

5 Comments

I got this error . Your application/config/database.php file does not appear to contain a valid configuration array.
Sorry my bad. this is the error. --- Unable to connect to your database server using the provided settings. Filename: C:\xampp\htdocs\site\system\database\DB_driver.php Line Number: 125
Check your database.php and provide your db details
@adulla thanks for the big help. I already figured out what's the problem. Till next time! have a good day.
@Glenn ok ok. Enjoy coding :)

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.