Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 963
Tri Murvianto Avatar asked Oct 26 '25 05:10

Tri Murvianto


1 Answers

You have a wrong syntax in these lines:

$key = $this->input->post('code');
$data['kd_prodi'] = $this->input->post['code']; // <-- use ('code')
$data['prodi'] = $this->input->post['jurusan']; // <-- use ('jurusan')

Change this to

$this->input->post['array_key'];

this

$this->input->post('array_key');

Read : Input Class in Codeigniter

like image 199
JMS786 Avatar answered Oct 28 '25 18:10

JMS786