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);
}
}
?>
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With