Not Able Insert Into Table

While trying to insert new entry into auth_assignment table I am getting following error CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens. The SQL statement executed was: INSERT INTO auth_assignment (itemname, userid, bizrule, data) VALUES(:itemname,:userid, :bizrule, :data)

Following is my code


public function actionCreate()

	{

		$user=new User;


		// Uncomment the following line if AJAX validation is needed

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


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

		{

			$user->setScenario('create');

			$user->attributes=$_POST['User'];

			if($user->save())

			{

				//*********************************************************************

				$connection=Yii::app()->db;

				$acID = $user->accountID;

				if($user->accessLevel == 0)

				{

					$sql="INSERT INTO auth_assignment (itemname, userid, bizrule, data) VALUES(:itemname,:userid, :bizrule, :data)";

					$command=$connection->createCommand($sql);

					$command->bindParam('superadmin',$itemname,PDO::PARAM_STR);

					$command->bindParam('hello',$userid,PDO::PARAM_STR);

					$command->bindParam('',$bizrule,PDO::PARAM_STR);

					$command->bindParam('',$data,PDO::PARAM_STR);

					$command->execute();

				}

				if($user->accessLevel == 1)

				{

					$sql="INSERT INTO auth_assignment (itemname, userid, bizrule, data) VALUES(:itemname,:userid, :bizrule, :data)";

					$command=$connection->createCommand($sql);

					$command->bindParam('admin',$itemnamename,PDO::PARAM_STR);

					$command->bindParam('hello',$userid,PDO::PARAM_STR);

					$command->bindParam('',$bizrule,PDO::PARAM_STR);

					$command->bindParam('',$data,PDO::PARAM_STR);

					$command->execute();

				}

				if($user->accessLevel == 2)

				{

					$sql="INSERT INTO auth_assignment (itemname, userid, bizrule, data) VALUES(:itemname,:userid, :bizrule, :data)";

					$command=$connection->createCommand($sql);

					$command->bindParam('Authenticated',$itemname,PDO::PARAM_STR);

					$command->bindParam('hello',$userid,PDO::PARAM_STR);

					$command->bindParam('',$bizrule,PDO::PARAM_STR);

					$command->bindParam('',$data,PDO::PARAM_STR);

					$command->execute();

				}

				//else

				//	return;

				//*********************************************************************

				$user->saveAttributes(array('creationTime' => date("Y-m-d H:i:s")));

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

			}

		}

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

			'user'=>$user,

		));

	}

Hi

According to

http://www.yiiframework.com/doc/api/1.1/CDbCommand#bindParam-detail

check this


 $sql="INSERT INTO auth_assignment (itemname, userid, bizrule, data) VALUES(:itemname,:userid, :bizrule, :data)";

                                        $command=$connection->createCommand($sql);

                                        $command->bindParam(':itemname',$itemname,PDO::PARAM_STR);

                                        $command->bindParam(':userid',$userid,PDO::PARAM_STR);

                                        $command->bindParam(':bizrule',$bizrule,PDO::PARAM_STR);

                                        $command->bindParam(':data',$data,PDO::PARAM_STR);

                                        $command->execute();



Make the other sql commands similar like that

I am doing it in the following way but the same error still shows up


if($user->accessLevel == 2)

				{

					$sql="INSERT INTO auth_assignment (itemname, userid, bizrule, data) VALUES(:itemname,:userid, :bizrule, :data)";

					$command=$connection->createCommand($sql);

					$command->bindParam(':itemnamename',$itemname = 'Authenticated',PDO::PARAM_STR);

					$command->bindParam(':userid',$userid = 'hello',PDO::PARAM_STR);

					$command->bindParam(':bizrule',$bizrule = null,PDO::PARAM_STR);

					$command->bindParam(':data',$data = null,PDO::PARAM_STR);

					$command->execute();

				}

change the

$command->bindParam(’:itemnamename’,$itemname = ‘Authenticated’,PDO::PARAM_STR);

to

$command->bindParam(’:itemname’,$itemname = ‘Authenticated’,PDO::PARAM_STR);

thanks KonApaz.