Would Like Some Help

Hi, I have this function in my model that inserts data into a database and then runs a static function to create Cloudflare SRV record. I’ve ran into an issue though where when I submit the form and it calls the function it does it multiple times so in the database it created about 5 records when it should only create one, same goes for the Cloudflare. Here’s my function in my model:




	public function create()

	{

		$model = Domains::model()->findByAttributes(array('domain_name'=>$this->domain_name));

		if ($model)

			Yii::app()->user->setFlash('error', 'Domain already exists. Please choose another.');

		if(!$model)

			$uid = "";

			$uid = CHtml::encode(sha1(str_shuffle('QWERTYUIOPASDFGHJKLZXCBNMqwertyuiopasdfghjklzxcvbnm1234567890-=[]')));

			Cloudflare::newR($uid, CHtml::encode($this->ip), CHtml::encode($this->domain_name), CHtml::encode($this->port));


			Yii::app()->panelDB->createCommand()->insert('domains', array(

				'username'=>CHtml::encode(Yii::app()->user->name),

				'domain_name'=>CHtml::encode($this->domain_name),

				'uid'=>CHtml::encode($uid),

				'ip'=>CHtml::encode($this->ip),

				'port'=>CHtml::encode($this->port),

			));

		Yii::app()->user->setFlash('success', 'Domain created!');

	}



SiteController:




	public function actionIndex()

	{

		$model = new Domains('Create');


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

		{

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

			if($model->validate())

			{

				$this->refresh();

			}

		}


		$this->render('index',array('model'=>$model));


	}



If anyone can help me that would be awesome.

You forgot to use curly brackets around your code block.

Btw all coding style guides disallow using short ‘if’ syntax.

And this is exactly what happens if you don’t follow one.

Yep, that worked, thanks for the help.