更新codeigniter中的数据时出错

时间:2014-03-27 03:40:18

标签: php codeigniter sql-update

我想要更新数据时收到错误。我是Codeigniter的新手,并不能真正弄清楚如何解决这个问题。错误显示

  

严重性:注意

消息:未定义的变量:tanggal,judul_berita,content

文件名:admin / berita.php

模型

function get_berita($limit = 1, $offset = 0)
    {
        $this->db->order_by('id_berita','asc');
        $data = $this->db->get($this->tbl_berita, $limit, $offset);
        return $data->result();
    }

function update_berita($id_berita,$data, $limit = 1, $offset = 0)
    {
        $this->db->where('id_berita', $id_berita);
        $this->db->update($this->tbl_berita, $data);
        $data = $this->db->get_where($this->tbl_berita, array('id_berita' => $id_berita), $limit, $offset);
        return $data->result();
    }

控制器

function edit_berita()
    {
        $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');

        $id_berita = $this->uri->segment(4);

        if ($this->form_validation->run() == FALSE) 
        {

            $data['id_berita'] = $id_berita;
            $data['tanggal'] = $tanggal;          //line error
            $data['judul_berita'] = $judul_berita; //line error
            $data['content'] = $content;  // line error
            $this->data['contents'] = $this->load->view('admin/berita/edit_berita', $data, true);
            $this->data['orang'] = $this->mlogin->dataPengguna($this->session->userdata('username'));
            $this->load->view('template/wrapper/admin/wrapper_ukm',$this->data);


        }else{

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

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

            );
            $this->mberita->update_berita($id_berita,$data);
            redirect(site_url('admin/berita'));
        }       
    }

请帮我做什么。谢谢

0 个答案:

没有答案