[SOLVED]Single Textfield and Storing in Two tables

I have got a form where i get a value through text field

i want to insert the same value into two tables

My register form


<div class="row">

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

		<?php echo $form->textField($model,'mobilenumber',array(

                                'type' => 'POST',

                                'url'=>CController::createUrl('PsmsEmpInfo/updateusername'),

								   )    

                        )   ;?>

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

	</div>

and my controller file


public function updateusername() 

          {

        

		 $username1 = $_GET['PsmsEmpInfo']['mobilenumber'];

		 

       $command = Yii::app()->db->createCommand();

        return $command->insert('PsmsUserAccInfo', array('username'=>"username1",'password'=>"username1"));


    }

Anyhow by doing this some null value is getting stored inside my second table and the exact value is getting stored only in the main table.

Can anyone help me

Don’t create a second action, use the main action for save both tables.

Take a look at this wiki.

I have done that earlier like


<div class="row">

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

		<?php echo $form->textField($model,'mobilenumber'); ?>

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

	</div>




<div class="row">

		<?php echo $form->labelEx($model2,'mobilenumber'); ?>

		<?php echo $form->textField($model2,'mobilenumber'); ?>

		<?php echo $form->error($model2,'mobilenumber'); ?>

	</div>



I can store it like that using two textfields using different models

But I want to get the value from one text field and store it in two tables and three columns

i.e

one column inside model

&

two columns inside second model

That’s why i went on to create another action in controller


public function updateusername() 

          {

        

                 $username1 = $_GET['PsmsEmpInfo']['mobilenumber'];

                 

       $command = Yii::app()->db->createCommand();

        return $command->insert('PsmsUserAccInfo', array('username'=>"username1",'password'=>"username1"));


    }

Something like this …




public function actionCreate()

{

    $a=new A;

    if(isset($_POST['A']))

    {

        // populate input data to $a

        $a->attributes=$_POST['A'];

 

        // validate $a

        $valid=$a->validate();

 

        if($valid)

        {

            // use false parameter to disable validation

            $a->save(false);

            // create another model instance

            $b=new B;

            // set the attribute of B using that of A

            $b->foo=$a->foo;

            $b->save(false);

            // ...redirect to another page

        }

    }

 

    $this->render('create', array(

        'a'=>$a,

    ));

}



Thanks softark for solving this prob for me… Now there is no need of a separate action like zaccaria said…