php - Issue with saving an update information in Codeigniter -
my goal update job_contract. there 2 ways should done. 1. through client's page , 2. through provider's page.
what have in job model is:
public function update_job_contract($post_obj) { $id = $post_obj['id']; $data = array ( 'client_feedback' => $post_obj['client_feedback'], 'client_notetoself' => $post_obj['client_notetoself'], 'contract_status' => $post_obj['contract_status'], 'client_id' => $this->auth_model->get_user_id() ); $this->db->insert('job', $data); } public function provider_update_job_contract($post_obj) { $id = $post_obj['id']; $data = array ( 'provider_feedback' => $post_obj['provider_feedback'], 'provider_notetoself' => $post_obj['provider_notetoself'], 'provider_id' => $this->auth_model->get_user_id() ); $this->db->insert('job', $data); }
i have following lines in client controller page:
public function update_job_contract() { $this->validaterole('client'); $this->load->model('job_model'); $id = $this->uri->segment(3,0); $data['job'] = $this->job_model->get_job($id); $this->load->view('client/update_job_contract', $data); } public function update_job_contract_submit() { $this->validaterole('client'); $this->load->model('job_model'); if ( '0' == $_post['id'] ) { $this->job_model->update_job_contract($_post); //} redirect('client/manage_job_contracts?message=congratulations!'); }
and in provider controller page:
public function provider_update_job_contract() { $this->validaterole('provider'); $this->load->model('job_model'); $id = $this->uri->segment(3,0); $data['job'] = $this->job_model->get_job($id); $this->load->view('provider/provider_update_job_contract', $data); } public function provider_update_job_contract_submit() { $this->validaterole('provider'); $this->load->model('job_model'); if ( '0' == $_post['id'] ) { $this->job_model->provider_update_job_contract($_post); } redirect('provider/job_contracts?message=congratulations!'); }
problem is, don't update entries. please help..
you using $this->db->insert()
, active record update row should using $this->db->update()
$data = array( 'title' => $title, 'name' => $name, 'date' => $date ); $this->db->where('id', $id); $this->db->update('mytable', $data);
another words functions should this:
public function update_job_contract($post_obj) { $id = $post_obj['id']; $data = array ( 'client_feedback' => $post_obj['client_feedback'], 'client_notetoself' => $post_obj['client_notetoself'], 'contract_status' => $post_obj['contract_status'], 'client_id' => $this->auth_model->get_user_id() ); $this->db->where('id', $id); $this->db->update('job', $data); } public function provider_update_job_contract($post_obj) { $id = $post_obj['id']; $data = array ( 'provider_feedback' => $post_obj['provider_feedback'], 'provider_notetoself' => $post_obj['provider_notetoself'], 'provider_id' => $this->auth_model->get_user_id() ); $this->db->where('id', $id); $this->db->update('job', $data); }
also, inside controllers $_post should replaced $this->input->post()
using 1 example:
public function provider_update_job_contract_submit() { $this->validaterole('provider'); $this->load->model('job_model'); $post = $this->input->post(); if ( '0' == $post['id'] ) { $this->job_model->provider_update_job_contract($post); } redirect('provider/job_contracts?message=congratulations!'); }
make sure update other controllers in same way
Comments
Post a Comment