tags:

views:

230

answers:

2

The MySQL Syntax Used

INSERT INTO friend_locations 
(user_id, lat, long) 
VALUES 
('82441', '28.665899', '-81.359756')

The MySQL Error Returned 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 'long) VALUES ('82441', '28.665899', '-81.359756')' at line 1

I don't understand this

UPDATE

the syntax coloring on this site made long stand out, that must be my issue

+6  A: 

You need to change

(user_id, lat, long)

to

(user_id, lat, `long`)

since the word long is a reserved word.

I try (but don't always remember) to just wrap all of my field names in backticks so I don't have to worry about that sort of thing.

Mark Biek
thanks I didnt know this, I notice that phpmyadmin does this when it does queries, I guess I confused the backticks with a regular ' instead of `
jasondavis
No problem. Frederico also makes a good point about field types in his comment on your question.
Mark Biek
A: 

If you quote your field-names with backticks, it ensures that MySQL doesn't confuse them with keywords:

INSERT INTO foo (`varchar`, `long`, bar) VALUES('zing', 2212323.02, 'yo mama!');

See MySQL docs on identifiers:

http://dev.mysql.com/doc/refman/5.0/en/identifiers.html

vezult