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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.