Jump to content

Archived

This topic is now archived and is closed to further replies.

jacobb

MYSQL query problem

Recommended Posts

I'm just a beginner and can not seem to get this information to post to the database I have setup.  I am trying create a private messaging script but I run into this problem. 

Here is the code:


[quote]conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
$db = mysql_select_db($dbname) or die(mysql_error());

$query =("INSERT INTO email (to , subject , message)
values('$to', '$subject', '$message')");
mysql_query($query,$conn) or die(mysql_error())
[/quote]



Here is the error message:

[quote]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 , subject , message) values('jake', 'test', 'test')' at line 1
[/quote]

I was hoping someone here could shed some light on this.  I have a different script that uses the exact same code and works fine.  I'm not sure what's going on.

Share this post


Link to post
Share on other sites
[b]to[/b] is a [b]reserved word[/b] in MySQL.  Don't use reserved words as field names.  Solution is to change the name to to mailto or sendto or anything but to (or any other reserved word).

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html in case you want the list of reserved words for future reference

Share this post


Link to post
Share on other sites
[quote author=AndyB link=topic=107848.msg433129#msg433129 date=1158104194]
[b]to[/b] is a [b]reserved word[/b] in MySQL.  Don't use reserved words as field names.  Solution is to change the name to to mailto or sendto or anything but to (or any other reserved word).

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html in case you want the list of reserved words for future reference
[/quote]

That worked.  Thank you.  Can someone please explain exactly what a reserved word is and what the reserved words are in MYSQL?

Share this post


Link to post
Share on other sites
[quote author=jacobb link=topic=107848.msg433131#msg433131 date=1158104563]
Can someone please explain exactly what a reserved word is and what the reserved words are in MYSQL?
[/quote]

Sure. That's the link in my initial response.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.