Welcome Guest, Not a member yet? Register   Sign In
Why these codes won't insert?
#1

[eluser]whygod[/eluser]
In MY_model,

Code:
function add_group() {
  $data = array(
     'name' => 'dentist' ,
     'description' => 'dentist' ,
  );
  
  $this->db->insert('groups', $data);
  
  if($this->db->affected_rows() > 0)
  {
   echo 'Data saved.';  
  }
  else
  {
   echo 'Data not saved.';
  }

}

In my controller:
Code:
function add_group() {
  $this->dental_model->add_group();
}

The problem here it doesn't insert the record.

When I execute this it says it saved the data successfully.
But when I checked if it really saved I don't see the newly inserted data.
Why?

Thank you very much in advanced.
#2

[eluser]xtremer360[/eluser]
First off you are saying the db insert is taking place in the MY_Model file but in your function call to the database you are calling the dental model. So I don't even know why you are getting a message back because it shouldn't be calling the right function inside the right model.
#3

[eluser]whygod[/eluser]
@xtremer360
core: MY_Model (The parent class)
model: dental_model

Hope it's clear to you now.



#4

[eluser]whygod[/eluser]
Okay,
I just forgot to set the database.php.

problem solved.
#5

[eluser]xtremer360[/eluser]
I don't understand though, according to your code the add group is inside of the dental model.
#6

[eluser]CroNiX[/eluser]
Which extends my_model...so anything available to my_model will be available to any other model that extends it. Just like a base controller or anything else in CI (or PHP for that matter) where you can override or extend the original function/method/parent class.




Theme © iAndrew 2016 - Forum software by © MyBB