Help Me Regarding Saving Registration Form Data

hi friends, this may be a very newbie question.

please help me.

i have two tables


user_id | name | age | experince

And another table called


id | user_id | comapany | exp | from_year | to_year

how to save the data in both tables after user submits the registration??

you can use this:

hi Mubashar Iqbal thanks for the reply

actually, i have the post data of the registration form for these two models like these


//the data are 





And for the experince table the data are






if i save profile model first then the experience id in the profile model will be null because i haven’t saved the experience table to relate with this profile model.

And if i save the experince model first then i wont get the user_id to relate with the profile model. I am confused please help

you can use transaction to do this job, first you will save the data in user table and find the last insert id(user_id) mention below to find the last inserted id. and than save the data in experience table.



    // than you can get id just like that


    $model->id // this is inserted item id



Do you want to save the all data through profile? if so, follow the steps:

  • create the profile form consisting the fields of Experience.



       <div class="row">

		<?php echo $form->labelEx($model,'company'); ?>

		<?php echo $form->textField($model,'company',array('size'=>60,'maxlength'=>128)); ?>

		<?php echo $form->error($model,'company'); ?>



  • declare variable into the model profile.


        public $company


  • in create action of the profile controller, set scenario variable of Experience


  • assign them (Experience’s variables) as safe into rules in the model of profile

array('company', 'safe'),

  • in create action of the profile controller, instantiate Experience model, assign them (Experience’s variables) in the Experience attributes.

	public function actionCreate()


        $model=new Profile();


 		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);






                           $exp = new Experience();

                           $exp->user_id = $model->primaryKey;

                           $exp->company = $model->company;










  • save and check the database, you’ll find the both table would be inserted.