Welcome Guest, Not a member yet? Register   Sign In
help here... fatal error in function..
#1

[eluser]mangpeps[/eluser]
guys need help here. I have tried several attempts to fix these but I just can't find a way.

Fatal error: Call to a member function insert() on a non-object in C:\xampp\htdocs\ci\application\models\blogmodel.php on line 23
#2

[eluser]danmontgomery[/eluser]
Not sure how you expect us to debug your code without seeing it, but the problem is that $this->db doesn't exist, so the database library isn't being properly loaded.
#3

[eluser]mangpeps[/eluser]
sorry for that...
here is my model..

<?php

class Blog_model extends Model {




function insert() {
parent::Model();




$data = array(
'salita' => $this->input->post('salita'),
'depinisyon' => $this->input->post('depinisyon') ,
'date' => $this->input->post('salita')
);

$this->db->insert('body',$data);

} }
?>
#4

[eluser]mddd[/eluser]
The error is because you are calling $this->db->insert() while the system doesn't know what $this->db is.
Have you loaded the database library?
#5

[eluser]danmontgomery[/eluser]
Code:
parent::Model();

This needs to be called in the constructor, not in a member function.

Code:
class Blog_model extends Model {

  function Blog_model() {
    parent::Model();
    $this->load->database();
  }

  function insert() {
    $data = array(
      ‘salita’ => $this->input->post(‘salita’),
      ‘depinisyon’ => $this->input->post(‘depinisyon’) ,
      ‘date’ => $this->input->post(‘salita’)
    );
      
    $this->db->insert(‘body’,$data);
  }
}




Theme © iAndrew 2016 - Forum software by © MyBB