Php Codeigniter脚本更新不工作
我有这个问题,控制器不会更改/更新数据库中的数据。我的桌子是(国家财富): no(primkey)| id|u country | year |金额 用于编辑的“我的视图”脚本:Php Codeigniter脚本更新不工作,php,codeigniter,Php,Codeigniter,我有这个问题,控制器不会更改/更新数据库中的数据。我的桌子是(国家财富): no(primkey)| id|u country | year |金额 用于编辑的“我的视图”脚本: <?php foreach($data->result() as $row){ ?> <a href="<?php echo base_url();?>index.php/wealth/edit/<?php echo $row->
<?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>
控制器从上面的我的表格中恢复数据后,数据将显示在下面的我的表格\u编辑\u文件中:
<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>
它将直接返回到“我的视图”页面,但问题是“什么都没有发生”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 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');
}
尝试在更新时转储所有值,并在最后设置exit()。为了确保所有的值都是正确的,并且都是有效的。顺便说一句,模型是供使用的!不要在控制器内设置所有逻辑,否则您将失去MVC的概念。谢谢,现在我使用的是模型,它工作正常。我的朋友说,如果我们在一个控制器中设置所有逻辑,它将运行得更快。但有时它也让我感到困惑。谢谢兄弟。
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');
}