I have this problem, the controller won't change/updated the data in the database. My table is (country_wealth):
no(primkey) | id_country | year | amount
My view script for edit:
<?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>
From the script above in my view file will continue to my controller:
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);
After the controller revived the data from my table above, the data will show in my form_edit_file below:
<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>
Then it will go to my controller (Update) after click the 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');
}
It will straight back to my view page, but the problem is "Nothing happened" a.k.a failed to updated the data in my table/database (None of the data in the table was changed). But there are no errors at all. That's what made me confused. I hope everybody can help me here...
Thank you,
Best regards,
Kris.
***** Note**: I'm not using model, all my model are in the controller.
My full script in the controller:
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');
}