3
votes

I'm creating a registering from. Whenever I try to insert data to db it throws this error.

A PHP Error was encountered Severity: Notice Message: Undefined property: insert_ctrl::$insert_model Filename: controllers/insert_ctrl.php Line Number: 38 Fatal error: Call to a member function form_insert() on a non-object in C:\xampp\htdocs\NewProject\application\controllers\insert_ctrl.php on line 38

This is my insert_ctrl.php

<?php

class insert_ctrl extends  CI_Controller{

    function _construct()
    {
        parent :: _construct();
        $this->insert_model->form_insert($data);

    }

    function index()
    {
        //Including validation library
        $this->load->library('form_validation');
        $this->form_validation->set_error_delimiters('<div class ="error">','</div>');

        //Validating name field
        $this->form_validation->set_rules('dname','Username','required|min_length[5]|max_length[15]');
        $this->form_validation->set_rules('demail','Email','required|valid_email');
        $this->form_validation->set_rules('dmobile','Mobile No.');
            $this->form_validation->set_rules('daddress','Adress','required|min_length[10]|max_length[50]');

            if($this->form_validation->run()==FALSE)
            {
                $this->load->view('insert_view');
            }
            else {
                //Setting values for db table
                $data=array(
                    'Student_Name'=>$this->input->post('dname'),
                    'Student_Email'=>$this->input->post('demail'),
                    'Student_Mobile'=>$this->input->post('dmoblie'),
                    'Student_Address'=>$this->input->post('daddress')

                );
                //Transfering data to model
                $this->insert_model->form_insert($data);
                //loading view
                $this->load->view('insert_view');
            }
        }
    }

//insert_model.php

<?php
class insert_model extends  CI_Model{
    function _construct()
    {
        parent :: _construct();


    }

    function form_insert($data)
    {
        $this->db->insert('student',$data);
    }
}
?>
4
Your code looks fine just change your constructor code into $this->load->model('insert_model');Harigovind R
I did that. But still it gives an errorAkisha
This is not even entering to insert_model.php Please help meeeAkisha

4 Answers

2
votes

You call wrong model function:

You call $this->load->model('Insert_model');

It means your model is Insert_model

instead of this:

 $this->insert_model->form_insert($data);

You use

$this->Insert_model->form_insert($data);

Change your constructor code to

function _construct()
    {
        parent :: _construct();
        $this->load->model('insert_model');

    }
2
votes

My controller-insert_ctrl.php

class insert_ctrl extends  CI_Controller{

function __construct()
{
    parent :: __construct();
    $this->load->model('insert_model');

}

function index()
{

        $this->insert_model->form_insert();
        echo "Clear";


}

}

My Model- insert_model.php

class insert_model extends  CI_Model{
    function __construct()
    {
        parent :: __construct();


    }

    function form_insert()
    {
        echo "model loaded Successfully";
    }
}

This model and controller has been named exactly as your. Check how the model has been loaded and called.

You can overcome the memory limit error by adding the following line of code on top of your php file.

ini_set("memory_limit","512M");

0
votes

Change this line

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

to

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

in config\autoload.php

-1
votes

Add this line: $this->load->model('modelName');

function __construct()
{
    parent :: __construct();
    $this->load->model('modelName');

}