سؤال

I am stuck with this for a few days now. Progress is, I could finally make my edit function work. However, I later realized, it works only once. If I try to edit another entry after the first successful edit/revision on something, it will no longer work.

Please tell me what's wrong..

Here's what I have in my controller:

public function edit_job() 
{
    $this->validateRole('client');
    $this->load->model('job_model');

    $id = $this->uri->segment(3,0);

    $data['my_preference'] = $this->array_to_select( $this->job_model->get_all_categories(), 'id','name');
    $data['job'] = $this->job_model->get_job($id);
    $this->load->view('client/edit_job', $data);
}   

public function edit_job_submit() 
{
    $this->validateRole('client');
    $this->load->model('job_model');

    if ( '0' != $_POST['id'] ) 
    {
        $this->job_model->edit_job($_POST);
    } else {
        $this->job_model->add_job($_POST);
    }
    redirect('client/manage_jobs?message=Job updated.');
}

in model:

  public function edit_job($obj)
{
    //allows client to edit/update his job details
     $data = array
    (
        'title' => $_POST['title'],
        'description' => $_POST['description'],
        'start_date' => date("Y-m-d", strtotime($_POST['start_date'])),
        'category_id' => $_POST['category_id']
    );
    $this->db->where('id', $id);
    $this->db->update('job', $data);    
}

Please please. Anyone help me on this please. Thanks!

هل كانت مفيدة؟

المحلول

It looks like your issue is the line

$this->db->where('id', $id);

You don't seem to be defining (or passing) $id in the edit_job in your model meaning it doesn't know what entry to update.

Give this a try

public function edit_job($obj)
{
    //allows client to edit/update his job details
    $id = $obj['id'];
     $data = array
    (
        'title' => $obj['title'],
        'description' => $obj['description'],
        'start_date' => date("Y-m-d", strtotime($obj['start_date'])),
        'category_id' => $obj['category_id']
    );
    $this->db->where('id', $id);
    $this->db->update('job', $data);    
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top