我遇到这个问题,控制器无法更改/更新数据库中的数据。我的表是( country_wealth ):
否(primkey)| id_country |一年|量
我的编辑视图脚本:
<?php
foreach($data->result() as $row){
?>
<a href="<?php echo base_url();?>index.php/wealth/edit/<?php echo $row->no; ?>" class="btn btn-warning">
<span class="glyphicon glyphicon-pencil"></span> Edit</a>
<?php }
}
?>
</p>
从我视图中的上述脚本文件将继续到我的控制器:
public function edit()
{
$this->load->model('m_login');
$level = $this->session->userdata('level');
$area =$this->session->userdata('Amount Edit');
$data['menu'] = $this->m_login->get_menu_for_level($level);
$data['title'] = 'Wealth Amount In This Country';
$data['content'] = 'wealth/v_wealth_edit';
$id = $this->uri->segment(3);
$this->db->from('country_wealth')
->where('no',$id);
$data['data'] = $this->db->get();
$this->load->view('v_home',$data);
控制器恢复上表中的数据后,数据将显示在我的form_edit_file中:
<form action="<?php echo base_url();?>index.php/wealth/update" method="post" class="form-horizontal" onsubmit="return CekForm();">
....
....
<button type="submit" name="save" id="save" class="btn btn-primary btn btn-success"><span class="glyphicon glyphicon-floppy-disk"></span> Save</button>
然后单击“保存”按钮后,它将转到我的控制器(更新):
public function update()
{
$key['no'] = $this->input->post('no');
$dt['id_country'] = $this->input->post('id_country');
$dt['year'] = $this->input->post('year');
$dt['amount'] = $this->input->post('amount');
$this->db->update('wealth_country',$dt,$key);
$this->session->set_flashdata('item_info', 'UPDATE SUCCED.');
redirect('wealth');
}
它将直接返回我的视图页面,但问题是&#34; 没有发生任何事情&#34; a.k.a未能更新我的表/数据库中的数据(表中没有任何数据被更改)。但是根本没有错误。是什么让我感到困惑。我希望每个人都能在这里帮助我......
谢谢,
致以最诚挚的问候,
克里斯。
*****注意**:我没有使用模型,我的所有模型都在控制器中。
我在控制器中的完整脚本:
public function edit()
{
$this->load->model('m_login');
$level = $this->session->userdata('level');
$area =$this->session->userdata('Amount Edit');
$data['menu'] = $this->m_login->get_menu_for_level($level);
$data['title'] = 'Wealth Amount In This Country';
$data['content'] = 'wealth/v_wealth_edit';
$id = $this->uri->segment(3);
$this->db->from('country_wealth')
->where('no',$id);
$data['data'] = $this->db->get();
$this->load->view('v_home',$data);
public function update()
{
$key['no'] = $this->input->post('no');
$dt['id_country'] = $this->input->post('id_country');
$dt['year'] = $this->input->post('year');
$dt['amount'] = $this->input->post('amount');
$this->db->update('wealth_country',$dt,$key);
$this->session->set_flashdata('item_info', 'UPDATE SUCCED.');
redirect('wealth');
}