Jump to content

mysql_query syntax error


Philwn

Recommended Posts

Hoping someone can help me, ive spent the last hour looking up examples of mysql_query(Insert) and changing my query but im still gettin a syntax error and I cant understand where. Ive tried removing apostrophies and putting the longest variable string outside of the speach marks without any joy.

 

mysql_query("INSERT INTO $QA_table (SUB_CATEGORY, QUESTION, FROM, FROM_EMAIL, DISPLAY) VALUES ('$sub_cat','$message','$from','$from_email','2')") or die(mysql_error());

 

 

I get the following 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 'FROM, FROM_EMAIL, DISPLAY) VALUES ('Range','test question bla bla bla','Phil','phi' at line 1

Link to comment
Share on other sites

FROM (the point in the query that is being called out in the error message) is a reserved mysql keyword, as in SELECT * FROM table_name.

 

You either need to rename your column to something else or you must enclose the column `FROM` in back-ticks every time you use it in a query.

Link to comment
Share on other sites

Thanks guys makes perfect sense, have changed the column name and works now.

 

While im at it You may be able to help with another question I have.

 

That code is part of a script processed by a form. each row has a column called ID which is the primary key and set to auto increment. Is there a way of after inserting the information into the table bringing back the ID number of that information entered or would I have to use a query to find the ID of the latest entry in the table.

 

I ask as if it was done using a query to find the id of the last table entry there would be a problem if two questions were submitted at the same time.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.