Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7584165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:51:18+00:00 2026-05-30T18:51:18+00:00

I have successful able to save data in User and Profile model, the problem

  • 0

I have successful able to save data in User and Profile model, the problem is in the Profile table only id and user_id is getting inserted, remaining fields in the profile eg, email, city are NULL. Please help me in sorting this, Please find the codes below:

Model:

user.php:

class User extends AppModel {
public $name = 'User';

var $hasOne = array('Profile' =>
                    array('className'    => 'Profile',
                          'conditions'   => '',
                          'order'        => '',
                          'dependent'    =>  true,
                          'foreignKey'   => 'user_id'
                    )
              );
.....

UsersController.php:

class UsersController extends AppController {
.....
public function add() {
    if ($this->request->is('post')) {
        $this->User->create();
        if ($this->User->save($this->request->data)) {
            if (!empty($this->request->data)) {
                $this->request->data['Profile']['user_id'] = $this->User->id;
                $this->User->Profile->save($this->request->data);
            }
            $this->Session->setFlash(__('The user has been saved'));
            $this->redirect(array('controller' => 'homes','action' => 'index'));
        } else {
            $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
        }
    }
}

View: add.ctp

            <?php echo $this->Form->create('User' , array('action' => 'add'));?>
            <fieldset>
                <?php
                    echo $this->Form->input('username');
                    echo $this->Form->input('password');
                    echo $this->Form->input('profile.firstname');
                    echo $this->Form->input('profile.lastname');
                    echo $this->Form->input('profile.email');
                ?>
            </fieldset>
            <?php echo $this->Form->end(__('Submit'));?>

Model: Profile.php:

class Profile extends AppModel {
public $name = 'Profile';
var $belongsTo = array('User' =>
                       array('className'  => 'User',
                             'conditions' => '',
                             'order'      => '',
                             'foreignKey' => 'user_id'
                       )
                 );
....

Please help.

Thanks in advance!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:51:19+00:00Added an answer on May 30, 2026 at 6:51 pm

    Update your form:

               <?php
                    echo $this->Form->input('username');
                    echo $this->Form->input('password');
                    echo $this->Form->input('Profile.firstname');
                    echo $this->Form->input('Profile.lastname');
                    echo $this->Form->input('Profile.email');
                ?>
    

    Also, the following if statement is overkill:

    if (!empty($this->request->data)) {
    

    clearly there is request data or you would not have gotten past the user save.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In SQL Server 2005, I have a table of input coming in of successful
I have been successful with creating a Telerik grid to display a list of
I have been successful at rounding my value to one decimal point, but I
I have been reading the MSDN documentation on subclassing and I have been successful
We have just completed implementing a successful but problematic project. We want to get
I have a login script that when successful, should check to see if the
I have big trouble with file uploads with php. My own tests are successful
I have a jQuery AJAX call with type:'GET' like this: $.ajax({type:'GET',url:'/createUser',data:userId=12345&userName=test, success:function(data){ alert('successful'); }
We use Perl for GUI test automation. It has been very successful. We have
I have created an sqlite table using the following statement: CREATE TABLE IF NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.