Codeigniter Database Error Number 1048 Values show NULL even though they are NOT NULL

Viewed 10779

I have situation where codeigniter shows database Error Number 1048. It seems Values NULL but when I try to check it usign var_dump($_POST) Values are not NULL.

Controller : Jurusan.php

public function simpan()
{
    $this->form_validation->set_rules('code','Kode','required|integer');
    $this->form_validation->set_rules('jurusan','Jurusan','required');
    $this->form_validation->set_rules('singkatan','Singkatan','required');
    $this->form_validation->set_rules('ketua','Ketua','required');
    $this->form_validation->set_rules('nik','NIK','required|integer');
    $this->form_validation->set_rules('akreditasi','Akreditasi','required');

    if($this->form_validation->run() == FALSE)
    {
        $isi['content'] = 'jurusan/form_tambahjurusan';
        $isi['judul'] = 'Master';
        $isi['sub_judul'] = 'Tambah Jurusan';
        $this->load->view('tampilan_home',$isi);
    } else {
        $this->model_security->getSecurity();

        $key = $this->input->post('code');
        $data['kd_prodi'] = $this->input->post['code'];
        $data['prodi'] = $this->input->post['jurusan'];
        $data['singkat'] = $this->input->post['singkatan'];
        $data['ketua_prodi'] = $this->input->post['ketua'];
        $data['nik'] = $this->input->post['nik'];
        $data['akreditasi'] = $this->input->post['akreditasi'];

        $this->load->model('model_jurusan');
        $query = $this->model_jurusan->getdata($key);

        if($query->num_rows()>0)
        {
            $this->model_jurusan->getupdate($key,$data);
        } else {
            $this->model_jurusan->getinsert($data);
        }

        redirect('jurusan');
    }   
}

Model : model_jurusan.php

class Model_jurusan extends CI_model {
    public function getdata($key)
    {
        $this->db->where('kd_prodi',$key);
        $hasil = $this->db->get('prodi');
        return $hasil;
    }

    public function getupdate($key,$data)
    {
        $this->db->where('kd_prodi',$key);
        $this->db->update('prodi',$data);
    }

    public function getinsert($data)
    {
        $this->db->insert('prodi',$data);
    }
}

Here is the error shown :

enter image description here

Here is the database structure :

enter image description here

4 Answers

i have tried your code...it works. I think there some mistakes in your <input> tags, You must use <input name=""> not <input id=""> or something else. Hope it can help you out

Related