0

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.)

3
Contributors
4
Replies
5
Views
4 Years
Discussion Span
Last Post by NardCake
0

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?

0

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?

1

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

0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.