Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
1  
On the one hand, you're missing a quote before $appdate'. On the other - you're using mysqli, so why aren't you using a prepared statement? –  andrewsi Aug 26 at 16:46
1  
You are wide open to sql injection attacks, consider using parameterized queries or at least calling mysqli_real_escape_string on your inputs. –  Orangepill Aug 26 at 16:48
add comment

3 Answers

You're missing a single quote before the $appdate variable in your query.

share|improve this answer
add comment

You forgot the ' character before $appdate'

'$stumajor',$appdate'

this should be '$stumajor','$appdate'

share|improve this answer
add comment

You are missing a quote in the following:

'$stumajor',$appdate','$appointment'

It should be

'$stumajor','$appdate','$appointment'
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.