Welcome Guest, Not a member yet? Register   Sign In
Model/Database question
#1

[eluser]Hamilogre[/eluser]
I'm trying to run an update in my model by passing $this to the $this->db->insert function. When I run it, it seems that it is trying to pass more than just my class variables to the insert statement. Here is the output:
Code:
An Error Was Encountered

Error Number: 1054

Unknown column '_parent_name' in 'field list'

INSERT INTO nsfma_doctor (_parent_name, doctor_first_name, doctor_middle_name, doctor_last_name, doctor_date_modified, _ci_ob_level, _ci_view_path, _ci_is_php5, _ci_is_instance, _ci_scaffolding, _ci_scaff_table) VALUES ('Doctor_model', 'kk', 'l', 'l', '07-08-18 12:34:24', 0, '/home/content/n/s/f/nsfma/html/system/application/views/', 0, 0, 0, 0)

Am I doing something wrong that is making it so that things outside of my class variables are being passed to the function?
#2

[eluser]Michael Wales[/eluser]
The best way to accomplish inserts and updates is to place all of your variables into an array and pass that array to the function:

Code:
$insert = array('doctor_first_name'=>$this->input->post('doctor_first_name'),
     'doctor_last_name'=>$this->input->post('doctor_last_name'));
$this->db->insert('nsfma_doctor', $insert);
#3

[eluser]Hamilogre[/eluser]
[quote author="walesmd" date="1187486358"]The best way to accomplish inserts and updates is to place all of your variables into an array and pass that array to the function:

Code:
$insert = array('doctor_first_name'=>$this->input->post('doctor_first_name'),
     'doctor_last_name'=>$this->input->post('doctor_last_name'));
$this->db->insert('nsfma_doctor', $insert);
[/quote]

Got ya. But isn't that repetitive? Because if I also want to set the class variables for the object I will need to set the separately...
#4

[eluser]Rick Jolly[/eluser]
Yup, just pass the $_POST array into the active record insert/update. That is providing that the data has been validated. Note that the validator class acts directly on the $_POST array, therefore once validation has been done, the $_POST array is safe.




Theme © iAndrew 2016 - Forum software by © MyBB