Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"error in your SQL syntax" - Using MySQL- Need help! 1

Status
Not open for further replies.

sbayter

IS-IT--Management
Nov 14, 2002
95
CO
Hi,
I am working on a survey which results will be saved into a MySQL Database.
When I submit the form it is giving me this error:
"You have an error in your SQL syntax near 'EXPLAIN) VALUES ('Question, '3', 12345, NULL)' at line 1"

Some of this value are send in a hidden field and other are typed by the user.
"Question" is a hidden, "3" is chosen by the user, "12345" y the client ref number which is hidden, and NULL is the explanation (the error).
The form has two types of question :radio groups form 0 to 10 and a text area to explain the choice of the radio group.
If I take the explain part out everything works fine and updates into the db but as soon as I put the text area in it gives me the previous error.
The statement is like this:

if ((isset($HTTP_POST_VARS["MM_insert"])) && $HTTP_POST_VARS["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO survey1typeq2 (QUESTION, ANSWER, CLIENT, EXPLAIN) VALUES (%s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['QUESTION'], "text"),
GetSQLValueString($HTTP_POST_VARS['ANSWER'], "text"),
GetSQLValueString($HTTP_POST_VARS['CLIENT'], "int"),
GetSQLValueString($HTTP_POST_VARS['EXPLAIN'], "text"));

Any help will be very appreciated.
Thanks,
sbayter
 
You are using a reserved word in your SQL: EXPLAIN.
You can use the backtick `EXPLAIN` to use reserved words within SQL statements.
However, it's easier to just not use reserved words as field, table, or database names.
 
Can you post the code that you used to create the database? There could be something with the way you created the "EXPLAIN" in that database. If I'm reading this right then it look like when you filled out the form you left EXPLAIN empty, thus the NULL; perhaps EXPLAIN requires an entry? Just an idea. When faced with a decision, always ask, 'Which would be the most fun?'
 
sbayter

Looking at the error I noticed that you only have one quote with Question
'EXPLAIN) VALUES ('Question, '3', 12345, NULL)'

Maybe try 'Question' and see if that fixes the problem. Binky ::)
><>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top