public function actionUpdateprofile(){
$user = User::model()->findByPk($_POST['User']['user_id']);
$profile = Profile::model()->findByPk($_POST['User']['user_id']);
if(isset($_POST['User']) || isset($_POST['Profile'])){
$user->attributes = $_POST['User'];
$profile->attributes = $_POST['Profile'];
$user->save();
$profile->save();
}
}
I did this code for update the value in profile and user table. But it's not working.
If i send $_POST['Profile']['email'] = '[email protected]';
There is no error but database still showed old value. why?
What i did wrong in there?
This is the result for $profile->attributes. email still have old value.
Array
(
[user_id] => 35
[lastname] => asd
[firstname] => asrtyr
[email] => xyz.gmail.com
[phoneno] => 123456
[prof_img] =>
[phoneno2] => 0
[agentKey] =>
[fb_id] =>
)
I suggest you to add error reporting like below
if(!$user->save()){
echo 'Error to save user model<br />';
var_dump($user->getErrors());
}
if(!$profile->save()){
echo 'Error to save profile model<br />';
var_dump($profile->getErrors());
}
I'd reccommend to check possible errors on saving:
istead of
$user->save();
you could use
if (!$user->save()){
print_r($user->getErrors());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With