I am currently working on a project using codeigniter. As part of the project functionalities, it have edit or update function and I got some errors with it, its not working.Here are my codes as follows :
Workers_model
This the edit function or update .
public function edit_workers_details ($worker_id, $data) {
$this->db->where('worker_id', $worker_id);
$this->db->update('worker_tb', $data);
return $this->db->affected_rows();
}
public function get_worker_details ($worker_id) {
$this->db->select();
$this->db->from('worker_tb');
$this->db->where('worker_id', $worker_id);
$query = $this->db->get();
return $query->result_array();
}
**Workers (controller)**
public function edit_worker ($worker_id) {
if ($_POST) {
$worker_details = array (
'worker_fname' => $_POST['worker_fname']
);
$this->Workers_model->edit_workers_details($worker_id, $worker_details);
redirect("Workers/index");
}
$data['details'] = $this->Workers_model->get_worker_details($worker_id);
$this->load->view('Worker/updateWorker',$data);
}
updateWorker (view)
<center>
<h1> Edit Worker Details </h1>
<?php foreach ($details as $detail) {?>
<form role="form" action= "<?php echo site_url("Workers/edit_worker/".$detail['worker_id']);?>" method="POST">
Name: <input type="text" class="form-control" value = "<?php echo $detail['worker_fname'];?>" ><br />
<button type="submit" class="btn btn-primary"> Update </button>
</form>
<?php } ?>
</center>
My problem now is that when I click the Update button it's not working and does not update data.What should I do? Any ideas or help is appreciated. Thanks