Jump to content


Photo

MYSQL query problem


  • Please log in to reply
4 replies to this topic

#1 jacobb

jacobb
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 September 2006 - 11:32 PM

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:


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




Here is the error message:

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


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.

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 September 2006 - 11:36 PM

to is a reserved word 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...rved-words.html in case you want the list of reserved words for future reference
Legend has it that reading the manual never killed anyone.
My site

#3 jacobb

jacobb
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 12 September 2006 - 11:42 PM

to is a reserved word 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...rved-words.html in case you want the list of reserved words for future reference


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

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 12 September 2006 - 11:55 PM

Can someone please explain exactly what a reserved word is and what the reserved words are in MYSQL?


Sure. That's the link in my initial response.
Legend has it that reading the manual never killed anyone.
My site

#5 jacobb

jacobb
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 13 September 2006 - 12:14 AM

oops....sorry I missed it.  Thank you




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users