Create User Fields Validation

username not inserting yar…, :( and also inserting 2 times…

not inserting username and inserting credentials 2 times yar…:(

if ur product table is just like this

tbl_product :

Columns : id,Productname, Brand, Cost,username

then why u use both $model->save() and then an insert query

once u have used $model->save() all columns values are saved

and this time u haven’t any value for username so thats why its empty for 1st row

but id is taken

on insert query again it saving values to product table so thats why 2 times inserting

and both times id takes value …

so simply do like this





if(isset($_POST['Product'])){


    $model->attributes=$_POST['Product'];

      $user_name = Yii::app()->user->name;

      $model->username = $username;

      if(!isset($_POST['Cost'])){

                $model->Cost = ''; 

        }


        if($model->save()){

        $this->redirect(array('view','id'=>$model->id));

        }

                        

  }