本文介绍了我无法在codeigniter中的数据插入数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法将资料插入资料库,也没有错误显示。我尝试var_dump($ this-> mberita-> get_berita());但是array(0){}。我是Codeigniter的新手,真的不知道如何解决这个问题。
i couldn't insert data to database and no error display. i try var_dump($this->mberita->get_berita()); but array(0){}. I am a newbie in Codeigniter and couldn't really figure out how to solve this.
modal
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);
}
控制器
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);
}
请帮助我做什么。
推荐答案
似乎可能缺少要插入的数据:
Seems you may be missing the data you want to insert:
$this->mberita->insert_berita($data);
这篇关于我无法在codeigniter中的数据插入数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!