shred_the_red
shred_the_red

Reputation: 23

Cakephp save inserting record instead of updating

I am trying to follow the cakephp 'saving your data' 2x cookbook but I am stumped. My UserController has a function Patient. My table is patientinformation. Below is a snippet of the code that I am using to save:

if (isset($this->request->data['patientinformation'])) {

       $this->patientinformation->create();
       $this->request->data['patientinformation']['UserID']=$this->Auth->user('id');
       $this->request->data['patientinformation']['Name']=$this->Auth->user('Name');

        } 
        $this->patientinformation->id['patientinformation']['id'];
        if ($this->patientinformation->save($this->patientinformation->id)){
           $this->Session->setFlash(__('Your information has been saved.'));
           $this->redirect(array('action' => 'index'));
        } else {

            $this->Session->setFlash(__('Your information could not be saved. Please, try again.'));

What I am hoping to do is to update a record if the id exists. I am not able to save my form data. Please let me know if I need to put additional information here.

Thank you.

Upvotes: 1

Views: 688

Answers (1)

Manwal
Manwal

Reputation: 23836

Are you sure your data saving in DB correctly???

This following line in your code doesn't make any sence:

$this->patientinformation->id['patientinformation']['id'];

Use this:

$this->patientinformation->id = $this->request->data['patientinformation']['id'];

In this section of your code $this->patientinformation->save($this->patientinformation->id) you are trying to save ID, but its completely incorrect way. You should save like following:

 $this->patientinformation->save($this->request->data['patientinformation']);

Upvotes: 4

Related Questions