0

我收到这样的错误

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Satuan, `Satuan`) VALUES (‘KMJ001’, ‘KKMJ005’, ‘asdf asdf’, ‘123123’, ‘kg’)’ at line 1

INSERT INTO `ms_material_jasa` (`Kode_Material_Jasa`, `Kode_Kategori_Material_Jasa`, `Nama_Jenis_Material_Jasa`, `Harga` Satuan, `Satuan`) VALUES (‘KMJ001’, ‘KKMJ005’, ‘asdf asdf’, ‘123123’, ‘kg’)

它指的是我的活动记录模型

function create($kmj,$kkmj,$njmj,$hs,$s)
{
    $data=array('Kode_Material_Jasa' => $kmj, 'Kode_Kategori_Material_Jasa' => $kkmj, 'Nama_Jenis_Material_Jasa' => $njmj, 'Harga Satuan' => $hs, 'Satuan' => $s);
    $this->db->insert('ms_material_jasa',$data);

}  

这是我的控制器

 function tambah()
{
   $data['kmj'] = $this->input->post('kmj');
   $data['kkmj'] = $this->input->post('kkmj');
   $data['njmj'] = $this->input->post('njmj');
   $data['hs'] = $this->input->post('hs');
   $data['s'] = $this->input->post('s');


   $data['title'] = 'QB Tambah Material / Jasa';
   $data['pesan'] = $data['kmj'].' berhasil ditambahkan ! ';


    $this->form_validation->set_rules('kmj','Kode Material / Jasa','trim|required|min_length[2]|max_length[20]|xss_clean');
    $this->form_validation->set_rules('kkmj','Kode Kategori Material / Jasa','trim|required|min_length[2]|max_length[20]|xss_clean');
    $this->form_validation->set_rules('njmj','Nama Jenis Material / Jasa','trim|required|min_length[2]|max_length[20]|xss_clean');
    $this->form_validation->set_rules('hs','Harga Satuan','trim|required|min_length[2]|numeric|max_length[20]|xss_clean');
    $this->form_validation->set_rules('s','Satuan','xss_clean');

    if($this->form_validation->run() == false)
    {
        $lastval = $this->m_admin->getlastval('KMJ','ms_material_jasa','kode_material_jasa');
        $data['nextval'] = $this->m_admin->gencode('KMJ',3,$lastval); 


        $this->load->view('head',$data);
        $this->load->view('content/add_material_jasa',$data);
    }
    else
    {

        $this->m_materialjasa->create($data['kmj'],$data['kkmj'],$data['njmj'],$data['hs'],$data['s']);
        $data['kirim'] = $this->m_materialjasa->read();
        $this->load->view('head',$data);
        $this->load->view('v/vkategorimaterial',$data);


    }

}  

看起来像下面的查询

INSERT INTO `ms_material_jasa` (`Kode_Material_Jasa`, `Kode_Kategori_Material_Jasa`, `Nama_Jenis_Material_Jasa`, `Harga` Satuan, `Satuan`) VALUES (‘KMJ001’, ‘KKMJ005’, ‘asdf asdf’, ‘123123’, ‘kg’)

是正确的,这是ms_material_jasa表格。看起来该条目不会破坏数据库上的数据 type.length 。我不知道出了什么问题,我该如何解决? 在此处输入图像描述

4

5 回答 5

0

您的报价在字段列表中的“Harga Satuan”上的位置错误。错误实际上是这样说的。你的:

INSERT INTO `ms_material_jasa` (`Kode_Material_Jasa`, `Kode_Kategori_Material_Jasa`, `Nama_Jenis_Material_Jasa`, `Harga` Satuan, `Satuan`) VALUES (‘KMJ001’, ‘KKMJ005’, ‘asdf asdf’, ‘123123’, ‘kg’)

正确的:

INSERT INTO `ms_material_jasa` (`Kode_Material_Jasa`, `Kode_Kategori_Material_Jasa`, `Nama_Jenis_Material_Jasa`, `Harga_Satuan`, `Satuan`) VALUES (‘KMJ001’, ‘KKMJ005’, ‘asdf asdf’, ‘123123’, ‘kg’)
于 2012-10-15T03:54:49.433 回答
0

您放置了错误的字段名称。请更正这一点,Harga_Satuan而不是Harga Satuan

function create($kmj,$kkmj,$njmj,$hs,$s)
{
    $data=array('Kode_Material_Jasa' => $kmj, 'Kode_Kategori_Material_Jasa' => $kkmj, 'Nama_Jenis_Material_Jasa' => $njmj, 'Harga_Satuan' => $hs, 'Satuan' => $s);
    $this->db->insert('ms_material_jasa',$data);

}  

你的查询应该是

INSERT INTO `ms_material_jasa` (`Kode_Material_Jasa`, `Kode_Kategori_Material_Jasa`, `Nama_Jenis_Material_Jasa`, `Harga_Satuan`, `Satuan`) VALUES (‘KMJ001’, ‘KKMJ005’, ‘asdf asdf’, ‘123123’, ‘kg’)
于 2012-10-15T03:55:40.107 回答
0

问题可能是听到'Harga Satuan' => $hs 没有这样的字段。

于 2012-10-15T03:56:30.917 回答
0

正确的是

INSERT INTO `ms_material_jasa` (`Kode_Material_Jasa`, `Kode_Kategori_Material_Jasa`, `Nama_Jenis_Material_Jasa`, `Harga Satuan`, `Satuan`) VALUES ('KMJ001', 'KKMJ005', 'asdf asdf', '123123', 'kg')
于 2012-10-15T14:11:10.737 回答
0

问题是活动记录未能将撇号放在HargaSatuan 中,

 $data=array('Kode_Material_Jasa' => $kmj, 'Kode_Kategori_Material_Jasa' => $kkmj, 'Nama_Jenis_Material_Jasa' => $njmj, 'Harga Satuan' => $hs, 'Satuan' => $s);
    $this->db->insert('ms_material_jasa',$data);

这可能是因为单词和数据库中的空格是带和下划线的。要更正此更改,请像这样更改代码。

function create($kmj,$kkmj,$njmj,$hs,$s)
{
  $data=array('Kode_Material_Jasa' => $kmj, 'Kode_Kategori_Material_Jasa' => $kkmj, 'Nama_Jenis_Material_Jasa' => $njmj, 'Harga_Satuan' => $hs, 'Satuan' => $s);
$this->db->insert('ms_material_jasa',$data);


}  

.

希望它能解决问题。

于 2014-04-14T14:40:58.217 回答