0

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.

2
  • 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? Commented Aug 26, 2013 at 16:46
  • 2
    You are wide open to sql injection attacks, consider using parameterized queries or at least calling mysqli_real_escape_string on your inputs. Commented Aug 26, 2013 at 16:48

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

You are missing a quote in the following:

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

It should be

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

Comments

1

You forgot the ' character before $appdate'

'$stumajor',$appdate'

this should be

'$stumajor','$appdate'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.