php - CodeIgniter insert two rows instead one -
i have issue codeigniter. reason insert 2 rows in database instead one.
below code model:
/** * add new fuel */ public function addnewfuel($id = null, $data) { if ($id) { var_dump('test'); $data = array( 'price' => '333' , 'fuel' => 'dizelka' , 'petrol_id' => '66' ); echo '<pre>'; print_r($data); echo '</pre>'; $this->db->insert('prices', $data); echo $this->db->last_query(); $this->db->insert('prices_archive',$data); return; } }
and here output:
string(4) "test" array ( [price] => 333 [fuel] => dizelka [petrol_id] => 66 )
edit:
this code controller calls model's function:
function addnewfuel() { if ($this->session->userdata('logged_in')) { $this->load->helper('form'); $id = $this->uri->segment(3); $fuel = $this->input->post('fuel'); $price = $this->input->post('price'); $addnewfuel = array('fuel' => $fuel, 'price' => $price); $data['addnewfuel'] = $this->adminarea_model->addnewfuel($id,$addnewfuel); $data['getfuels'] = $this->adminarea_model->getfuels(); $data['getpetrolnamebyid'] = $this->adminarea_model->getpetrolnamebyid(); $data['getpetrolinformation'] = $this->adminarea_model->getpetrolinformation(); $this->load->view('admin/edit', $data); } else { //if no session, redirect login page redirect('login', 'refresh'); } }
for reasons in table 'prices' i'm getting 2 rows same data, , don't have idea why happens.
thanks
you inserting data both controller model.
remove model, hope ill solve problem. thanks
$data = array( 'price' => '333' , 'fuel' => 'dizelka' , 'petrol_id' => '66' );
Comments
Post a Comment