1

I've tried to insert data using database and table fields where naming the database uses spaces (this is from my office law). But there is a following error -
'Error Number: 1064 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 'harian_copy1 (RecID, id_peminjaman, Tanggal, Cabang, Jenis Proyek,' at line 1'.

Controller:

public function inputalokasiharian() {
// Ambil data dari form atau sumber lainnya
    
    $RecID = $this->input->post('RecID');
    $id_peminjaman = $this->input->post('id_peminjaman');
    $Tanggal = $this->input->post('Tanggal');
    $Cabang = $this->input->post('Cabang');
    $Jenis_Proyek = $this->input->post('Jenis Proyek');
    $Nama_Proyek = $this->input->post('Nama Proyek');
    $Kode_Proyek = $this->input->post('Kode Proyek');
    $Jenis_Alokasi = $this->input->post('Jenis Alokasi');
    $Nama_Alokasi = $this->input->post('Nama Alokasi');
    $Jenis_Pekerjaan = $this->input->post('Jenis Pekerjaan');
    $keterangan = $this->input->post('keterangan');
    $persentase_hasil = $this->input->post('persentase_hasil');
    $jam_mulai = $this->input->post('jam_mulai');
    $jam_selesai = $this->input->post('jam_selesai');
    $ketercapaian = $this->input->post('ketercapaian');
    $bagian = $this->input->post('bagian');
    

    $data = array(
        'RecID' => $RecID,
        'id_peminjaman' => $id_peminjaman,
        'Tanggal' => $Tanggal,
        'Cabang' => $Cabang,
        'Jenis Proyek' => $Jenis_Proyek,
        'Nama Proyek' => $Nama_Proyek,
        'Kode Proyek' => $Kode_Proyek,
        'Jenis Alokasi' => $Jenis_Alokasi,
        'Nama Alokasi' => $Nama_Alokasi,
        'Jenis Pekerjaan' => $Jenis_Pekerjaan,
        'keterangan' => $keterangan,
        'persentase_hasil' => $persentase_hasil,
        'jam_mulai' => $jam_mulai,
        'jam_selesai' => $jam_selesai,
        'ketercapaian' => $ketercapaian,
        'bagian' => $bagian
    );

    $this->region_model->insertalokasiharian($data);
    $this->session->set_flashdata('message_input_ah','<div class="alert alert-success alert-dismissible mt-1 fade show" role="alert">Data alokasi harian berhasil dimasukkan
                                                          <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                                              <span aria-hidden="true">&times;</span>
                                                          </button>
                                                     </div>');
    redirect($_SERVER['HTTP_REFERER']);
}

Model:

public function insertalokasiharian($data) {
    $DB2 = $this->load->database('old_db', TRUE);
    return $DB2->insert('`ga - alokasi harian_copy1`', $data);
}
3
  • try wrapping the column names having spaces with backticks. Does this help? stackoverflow.com/questions/40232712/… Commented Nov 21, 2023 at 3:42
  • but how to implement in codeigniter 3? Commented Nov 21, 2023 at 8:05
  • 1
    something like this '`Jenis Proyek`' => $Jenis_Proyek Commented Nov 21, 2023 at 8:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.