Cannot Figure Out INSERT Query Error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
zunebuggy
Forum Commoner
Posts: 41
Joined: Wed Aug 27, 2008 1:22 pm

Cannot Figure Out INSERT Query Error

Post by zunebuggy »

I cannot figure out why my INSERT query has an error.

Here is my table schema:
  • text_field1 text
    text_field2 text
    text_field3 text
    text_field4 text
    created_date datetime
    bool1 tinyint(1)
    num_of_days int(11)
    bool2 tinyint(1)
    bool3 tinyint(1)
    bool4 tinyint(1)
    name_field1 varchar(25)
    long_msg1 longtext
Here is my INSERT query

Code: Select all

 
mysql_query("INSERT INTO msgtbl (text_field1, text_field2, text_field3, text_field4, created_date, bool1, num_of_days, bool2, bool3, bool4, name_field1, long_msg1')
VALUES ('$text_val1', '$text_val2', '$text_val3', '$text_val4', CURDATE(), '0', '7', '1', '1', '0', '$name_val1', '$my_msg')") or die(mysql_error());
 
NOTE:With the CURDATE() I am attemping to populate the datetime type field with a current date and time stamp. The 5 values after that are not variables but literal values. The rest with the preceedig $ are of course php variables.

And here is the error it is returning:
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 '') VALUES ('4883032953', 'Anonymous', 'Anonymous', 'No Subject', CURDATE(), '0'' at line 1
What do I have malformed in my sql query?

Thank you.
-Joe
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Cannot Figure Out INSERT Query Error

Post by Benjamin »

You have a ' after long_msg1
zunebuggy
Forum Commoner
Posts: 41
Joined: Wed Aug 27, 2008 1:22 pm

Re: Cannot Figure Out INSERT Query Error

Post by zunebuggy »

Thank you very much! That is all it was.... Something that small caused all my gray hairs last night :)
Post Reply