I have some problem when submitting the _form.php to SiteController.php this error message will appear,
"CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; "
It cannot run the query. Also try with another query command, the error is same.
SiteController.php
public function actionCreate()
{
$model = new Detail;
if (isset($_POST['Detail'])) {
// print_r($_POST['Detail']);
$model->attributes = $_POST['Detail'];
$connection = Yii::app()->db;
$data = date('Y-m-d');
$date = "'" . $data . "'";
$teach_id = Yii::app()->user->getId();
$i = 1;
foreach ($_POST['Detail'] as $stud=>$status)
{
$sql = 'INSERT INTO {{detail}} (`id`, `student_id`, `teacher_id`, `date`, `status`) VALUES
(NULL, ' . $stud . ',' . $teach_id . ',' . $date . ', ' . $i . ' );';
$command = $connection->createCommand($sql);
$exec = $command->query();
}
if ($exec) {
$this->redirect(array('index'));
}
}
$this->render('create', array('model' => $model, ));
}