Jump to content

MYSQL query problem


jacobb

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.
Link to comment
https://forums.phpfreaks.com/topic/20568-mysql-query-problem/
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
Link to comment
https://forums.phpfreaks.com/topic/20568-mysql-query-problem/#findComment-90768
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?
Link to comment
https://forums.phpfreaks.com/topic/20568-mysql-query-problem/#findComment-90770
Share on other sites

Archived

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

×
×
  • Create New...

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.