Hello! I'm working on a simple messaging system for a project and I have this query and it isn't working for some odd reason, here it is:

mysql_query("INSERT INTO messages SET
                        user='$user',
                        message='$msg',
                        date='$date',
                        to='$id',
                        private='$checked'
                        ")

Here is my 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 'to='4', private='0'' at line 5

Not quite sure what it's saying, I'm not trying anything new I'm using the same syntax as I always do in my queries. But I know me I might just need someone to point something obvious out, but who knows. Thanks for any help, and sorry if it's obvious! (And yes I have tested all variables being used, they are valid.)

Recommended Answers

All 4 Replies

it looks to me that $checked = a variable with an extra ' in it. It says it in the message (private='0'') with the extra aposrophe. Maybe thats why?

Nope thats not it, echoed it out, it's an integer as it was supposed to be. Thanks for the suggestion though! Any other ideas anyone?

Nothing is standing out, the only thing I can think of is mix-matching a field. Make sure your DB cols are of the correct type for the data your supplying... i.e. the to col isn't of type CHAR or something to the effect

GliderPilot, thanks for bringing that to mind. That was indeed the issue, you see the $id value placed in the private field was not the correct data. After tracing it back from a javascript file to another PHP file I have discovered I have used the incorrect variable. Thanks for the suggestions!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.