gpt4 book ai didi

php - 我无法在 codeigniter 中将数据插入数据库

转载 作者:行者123 更新时间:2023-11-29 06:39:06 25 4
gpt4 key购买 nike

我无法将数据插入数据库并且没有错误显示。我尝试 var_dump($this->mberita->get_berita());但是数组(0){}。我是 Codeigniter 的新手,无法真正弄清楚如何解决这个问题。

模态

function get_berita()
{
$this->db->order_by('id_berita','asc');
$data = $this->db->get('berita_ukm');
return $data->result();
}

//untuk menambah berita
function insert_berita($data)
{
$this->db->insert('berita_ukm', $data);
}

Controller

function index()
{
$this->data['berita'] = $this->mberita->get_berita();
$this->data['title'] ='UKM Taekwondo | berita';
$this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
$this->data['contents'] = $this->load->view('admin/berita/view_berita', $this->data, true);
$this->load->view('template/wrapper/admin/wrapper_ukm',$this->data);
}



function tambah_berita()
{

$this->form_validation->set_rules('id_berita', 'Id Berita', 'required|numeric');
$this->form_validation->set_rules('tanggal', 'Tanggal', 'required');
$this->form_validation->set_rules('judul_berita', 'Judul Berita', 'required');
$this->form_validation->set_rules('content', 'Content', 'required');

if ($this->form_validation->run() == FALSE)
{
$this->load->view('admin/berita/tambah_berita');

}else{

$this->load->model('mberita');

$data = array(
'id_berita' => $this->input->post('id_berita'),
'tanggal' => $this->input->post('tanggal'),
'judul_berita' => $this->input->post('judul_berita'),
'content' => $this->input->post('content')

);

$this->mberita->insert_berita($data);
}

$this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
$this->data['contents'] = $this->load->view('admin/berita/tambah_berita', '', true);
$this->load->view('template/wrapper/admin/wrapper_ukm',$this->data);
}

请帮我看看该怎么做。谢谢。

最佳答案

似乎您可能缺少要插入的数据:

$this->mberita->insert_berita($data);

关于php - 我无法在 codeigniter 中将数据插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22649818/

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