gpt4 book ai didi

php - Codeigniter 数据库错误编号 1048 值显示 NULL,即使它们不是 NULL

转载 作者:可可西里 更新时间:2023-11-01 08:03:13 27 4
gpt4 key购买 nike

我遇到了 codeigniter 显示数据库错误号 1048 的情况。似乎值为 NULL,但是当我尝试检查它时使用 var_dump($_POST) 值不为 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_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);
}
}

这是显示的错误:

enter image description here

这是数据库结构:

enter image description here

最佳答案

这些行中的语法错误:

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

将此更改为

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

这个

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

阅读:Input Class in Codeigniter

关于php - Codeigniter 数据库错误编号 1048 值显示 NULL,即使它们不是 NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45384393/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com