0

I'm trying to insert user inputted values as well as a string that is a combination of the month year of the start date + the user inputted quarter. What is wrong. please help!!!!!

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "addUser")) {
$date=  $_POST['start_date'];
$d=date_parse_from_format("Y-m-d",$date);
  $insertSQL = sprintf("INSERT INTO contacts (USER_NAME, START_DATE, THREE_MONTH, SIX_MONTH, TWELVE_MONTH, QUARTER, ORDER) VALUES (%s, %s, %s, %s, %s, %s,'".$d["month"].$d["year"].$_POST['quarter']."' )",
                       GetSQLValueString($_POST['user'], "text"),
                       GetSQLValueString($_POST['start_date'], "date"),
                       GetSQLValueString($_POST['3month'], "date"),
                       GetSQLValueString($_POST['6month'], "date"),
                       GetSQLValueString($_POST['12month'], "date"),
                       GetSQLValueString($_POST['quarter'], "text"));

error i'm getting:

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 'ORDER) VALUES ('boobz', '2013-11-22', '2013-11-29', '2013-11-23', '2013-11-02', ' at line 1

5
  • 9
    ORDER is a reserved word in SQL. If you really must use it, you'll need to quote it with backticks; but it makes for a much easier time if you avoid naming columns and tables after reserved words in the first place. Commented Jul 24, 2013 at 19:19
  • Can you show us, what you have in $insertSQL variable? Commented Jul 24, 2013 at 19:19
  • @andrewsi Why not make an answer? Commented Jul 24, 2013 at 19:20
  • @Shredder - I can generally only pop on to SO for a couple of minutes now and again; I don't like putting up a half-hearted answer, so I mostly stick to comments. Commented Jul 25, 2013 at 1:11
  • @andrewsi Was as full as the ones below ;) I feel ya tho Commented Jul 25, 2013 at 15:45

2 Answers 2

2

ORDER is reserved word. Use ` or better change it to something else in database structure. That's better practice.

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

Comments

2

Order is a reserved word, you need to quote it with backticks:

INSERT INTO contacts (USER_NAME, START_DATE, THREE_MONTH, SIX_MONTH, TWELVE_MONTH, QUARTER, `ORDER`)

Or better yet, do not use the reserved word and use something more sensible.

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.