# Why is my data not getting saved into my database?

**URL:** https://discourse.cakephp.org/t/why-is-my-data-not-getting-saved-into-my-database/9739
**Category:** Need Help
**Created:** [September 24, 2021, 4:02pm UTC](https://discourse.cakephp.org/t/why-is-my-data-not-getting-saved-into-my-database/9739 "2021-09-24T16:02:02Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)
#### Post date: [September 24, 2021, 4:02pm UTC](https://discourse.cakephp.org/t/why-is-my-data-not-getting-saved-into-my-database/9739/1 "2021-09-24T16:02:02Z")

</div>

Hi, i am working on a edit function in my UsersController but the value that i provide will not being updated inside of my database even if the object has got the correct value:

Controller:  
$user-\>profile-\>image = $name;  
debug($user);  
exit;  
}  
}

```
    if ($this->Users->save($user)) {
        $this->Flash->success(__('The user has been saved.'));
        
        return $this->redirect(['action' => 'index']);
    }
    $this->Flash->error(__('The user could not be saved. Please, try again.'));
}
$this->set(compact('user'));

```

* * *

APP/Controller/UsersController.php (line 167)  
object(App\Model\Entity\User) id:0 {  
‘id’ =\> (int) 22  
‘created’ =\> object(Cake\I18n\FrozenTime) id:1 { }  
‘modified’ =\> object(Cake\I18n\FrozenTime) id:2 { }  
‘profile’ =\> object(App\Model\Entity\Profile) id:3 {  
‘id’ =\> (int) 20  
‘user\_id’ =\> (int) 22  
‘name’ =\> ‘Mike’  
‘image’ =\> ‘681668.jpg’

The value ‘image’ of the object is correct here but he does not write it into the database. If I change other values it will work fine. just the value that i write into the object with  
$user-\>profile-\>image = $name; will not being updated inside of the database.

---

<div class="post-metadata">

### Author: ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)
#### Post date: [September 24, 2021, 4:11pm UTC](https://discourse.cakephp.org/t/why-is-my-data-not-getting-saved-into-my-database/9739/2 "2021-09-24T16:11:51Z")

</div>

If you recently added the `image` column, you need to clear your model cache.

---

<div class="post-metadata">

### Author: ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)
#### Post date: [September 24, 2021, 4:13pm UTC](https://discourse.cakephp.org/t/why-is-my-data-not-getting-saved-into-my-database/9739/3 "2021-09-24T16:13:23Z")

</div>

You might also need to `$user->setDirty('profile', true)` so that the user record knows that there’s an update in the profile that needs to be saved.

---

<div class="post-metadata">

### Author: ![Herzberg](https://avatars.discourse-cdn.com/v4/letter/h/74df32/32.png) [@Herzberg](https://discourse.cakephp.org/u/Herzberg)
#### Post date: [September 24, 2021, 4:48pm UTC](https://discourse.cakephp.org/t/why-is-my-data-not-getting-saved-into-my-database/9739/4 "2021-09-24T16:48:23Z")

</div>

okay thank you! now its working…
