CodeIgniter插入两行而不是一行

时间:2015-03-16 21:37:37

标签: php mysql codeigniter

CodeIgniter存在问题。由于某种原因,它在数据库中插入两行而不是一行。

以下是型号的代码:

/**
* 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;
    }

}

这是输出:

string(4) "TEST"
Array
(
    [price] => 333
    [fuel] => dizelka
    [petrol_id] => 66
)

编辑:

这是来自控制器的代码,它调用模型的功能:

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 to login page
        redirect('login', 'refresh');
    }
}

由于某些原因,在表中列出了价格&#39;我得到两行有相同数据的行,我真的不知道为什么会这样。

由于

1 个答案:

答案 0 :(得分:0)

您正在从控制器和模型中插入数据。

从模型中删除它,希望它解决问题。感谢

 $data = array(
       'price' => '333' ,
       'fuel' => 'dizelka' ,
       'petrol_id' => '66'
    );
相关问题