Forum Moderators: coopster

Message Too Old, No Replies

Mysql syntax error

Can't find whats wrong

         

nfs2

1:39 pm on Mar 12, 2006 (gmt 0)

10+ Year Member



This code is giving me the error "you have an error in your sql syntax. Check the manual bla bla bla..."

Here's the code

$table = 'messages';
$sql = "INSERT INTO $table (from, to, title, message, time) values ('$from', '$to', '$title', '$message', '$time')";
mysql_query($sql) or die(mysql_error());

Now, to state the obvious, all variables are defined and working. The table and all feilds exist and should work. I also use a very similar code elsewhere on the site with noo problems.

Anyone know whats wrong?

zCat

1:43 pm on Mar 12, 2006 (gmt 0)

10+ Year Member



no, but you could try printing the $sql string to see exactly what statement is being issued. This might reveal more clues.

Birdman

1:46 pm on Mar 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Probably due to the names you've chosen for the fields. I think some are reserved SQL words. Try this:

$sql = "INSERT INTO `$table` (`from`, `to`, `title`, `message`, `time`) values ('$from', '$to', '$title', '$message', '$time')";

Note that those are backticks (top left on your keyboard).

nfs2

1:51 pm on Mar 12, 2006 (gmt 0)

10+ Year Member



It shows exactly what it should.. It shoud work..

INSERT INTO messages (from, to, title, message, time) values (me', 'you', 'title test', 'message test', 'March 12, 2006, 7:49 am')

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, to, title, message, time) values ('me', 'you', 'title test', 'message t' at line 1

nfs2

1:51 pm on Mar 12, 2006 (gmt 0)

10+ Year Member



Ok Birdman ill try now

//EDIT

That worked great! Thanks! =)