简体   繁体   中英

MySql syntax error, insert

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM