Reputation: 25
When the date need to insert into mysql table, it prompt this error-
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '','2013-09-11','1', NULL)' at line 2
This is my source code:
if(isset($_POST['submitsub']))
{
$stuid = $_POST['stuid'];
$stuname = $_POST['stuname'];
$stuemail = $_POST['stuemail'];
$stumajor = $_POST['stumajor'];
$appdate = date("Y-m-d");
$appointment = $_POST['date'];
$subno = $_POST['subject'];
$appstatus = 1;
$tri = mysqli_fetch_assoc(mysqli_query($con,"SELECT this_tri FROM trimester"));
$sql = "INSERT INTO application_subject (app_no, tri_id, sub_id, stu_id, stu_name, stu_email, stu_major, app_date, appointment_date, app_status, app_remark)
VALUES (NULL,'$tri[this_tri]','$subno','$stuid','$stuname','$stuemail','$stumajor',$appdate','$appointment','$appstatus', NULL)";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo'<script>alert("Your application has been submited") </script>';
ob_flush();
}
On my mysql, the attribute of is set to date already.
Upvotes: 0
Views: 819
Reputation: 58
You forgot the '
character before $appdate'
'$stumajor',$appdate'
this should be
'$stumajor','$appdate'
Upvotes: 1
Reputation: 50
You are missing a quote in the following:
'$stumajor',$appdate','$appointment'
It should be
'$stumajor','$appdate','$appointment'
Upvotes: 1
Reputation: 1489
You're missing a single quote before the $appdate variable in your query.
Upvotes: 1