Home > Back-end >  A Database Error Occurred, Insert data from select option code igniter
A Database Error Occurred, Insert data from select option code igniter

Time:12-18

I'm add field data from another table, I put the data on select option. I want save it but database error "nik = null".

this my error

Column 'nik' cannot be null

INSERT INTO `tbl_kotak` (`nik`, `nama_kotak`, `lokasi`) VALUES (NULL, 'GM 1.3', 'Garment 1')

My Controller

function tambah_aksi()
    {
        $nik = $this->input->post('nik');
        $nama_kotak = $this ->input->post('nama_kotak');
        $lokasi = $this->input->post('lokasi');

        $data = array (
            'nik' => $nik,
            'nama_kotak' => $nama_kotak,
            'lokasi' => $lokasi
        );

        $this->m_kotak->input_data($data,'tbl_kotak');

        redirect('kotak/index');
    } 

My Model

function get_pic(){
        $this->db->order_by('nik','asc');
        return $this->db->from('tbl_karyawan')
                ->get()
                ->result();
}

Thank You

CodePudding user response:

You have to make sure $nik has the valid value try to echo $nik

CodePudding user response:

Please mention your input_data() function code, table structure and also mention view file code for better understanding and result.

  • Related