Yii Framework Forum: Create User Fields Validation - Yii Framework Forum

Jump to content

  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

Create User Fields Validation Validation in yii Rate Topic: -----

#21 User is offline   Latha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 17-June 13

Posted 25 June 2013 - 05:28 AM

View PostLal Zada, on 25 June 2013 - 05:17 AM, said:

try this


$sql="INSERT INTO tbl_user (username, email) VALUES(:username,:email)"; 
$command=$connection->createCommand($sql); 
$command->bindParam(":username",$username,PDO::PARAM_STR); 
$command->bindParam(":email",$email,PDO::PARAM_STR);
$command->execute();




username not inserting yar.., :( and also inserting 2 times...
0

#22 User is offline   Latha 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 17-June 13

Posted 25 June 2013 - 05:35 AM

View PostLal Zada, on 25 June 2013 - 05:17 AM, said:

try this


$sql="INSERT INTO tbl_user (username, email) VALUES(:username,:email)"; 
$command=$connection->createCommand($sql); 
$command->bindParam(":username",$username,PDO::PARAM_STR); 
$command->bindParam(":email",$email,PDO::PARAM_STR);
$command->execute();




not inserting username and inserting credentials 2 times yar..:(
0

#23 User is offline   Lal Zada 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 125
  • Joined: 06-November 12
  • Location:Lahore, Pakistan

Posted 26 June 2013 - 01:58 AM

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));
        }
                        
  }




Is it fast? Is it secure? Is it professional? Is it right for my next project? Yes, it is

Linkedin Facebook Twitter Google+
0

Share this topic:


  • (2 Pages)
  • +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users