Welcome Guest, Not a member yet? Register   Sign In
Getting erro when I try to insert into data to db
#1

[eluser]matches[/eluser]
Hello,

I am still pretty new to CI. I am trying to update a users table with the following code

Code:
class register extends Controller {
    
    function register()
    {
        parent::Controller();
        
        $this->load->helper('url');
        $this->load->helper('form');
    }
    
    function index()
    {
        $this->load->view('register/index');
    }
    
    function loadData()
    {
        $this->db->insert('users', $_POST);
    }
}

But getting this error:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: register::$db

Filename: controllers/register.php

Line Number: 27

Fatal error: Call to a member function insert() on a non-object in C:\xampp\htdocs\TEST\system\application\controllers\register.php on line 27

This is line 27 in the code above:

$this->db->insert('users', $_POST);

Thanks for any help!
#2

[eluser]Jamie Rumbelow[/eluser]
Hey, matches!

Make sure that you have either autoloaded the database library, or use the $this->load->database() function in your controller!

Jamie




Theme © iAndrew 2016 - Forum software by © MyBB