/** * Creates a new Pic model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Pic(); if ($model->load(Yii::$app->request->post())) { $a = $model->pic_fullName; $connection = \Yii::$app->db; $sql = $connection->createCommand('SELECT pic_fullName FROM Pic WHERE pic_fullName = "' . $a . '"')->queryAll(); if ($sql != null) { echo "<SCRIPT LANGUAGE='JavaScript'>\n\t\t\t\t\t\twindow.alert('This Person has already existing in the database')\n\t\t\t\t\t\twindow.location.href='index.php?r=project%2Findex';\n\t\t\t\t\t\t</SCRIPT>"; } else { $model->save(); return $this->redirect(['project/index']); } } else { return $this->renderAjax('create', ['model' => $model]); } //echo "<a href='index.php?r=project%2Findex'> Go Back</a>"; }