[SOLVED] what the HECK!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

[SOLVED] what the HECK!!!

Post by Jr »

Ok, I have a simple mysql_query("INSERT") that looks like this:

Code: Select all

$to = "1";
$subject = "Report Post";

$result = mysql_query("INSERT INTO pm_box (to, from, subject, message, date) VALUES('$to', '$user_input', '$subject', '$message', '$date')")
or die(mysql_error());
But it keeps giving me this error saying the mysql code is wrong:

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, from, subject, message, date) VALUES('1', 'Jr', 'Report Pos

I just can't figure out what's wrong with this thing. Could it be something incorrect with the database? The CPanel MyAdmin thing let me set up the DB just fine so I really dont get it.

Jcart | Please review how to post code here
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Moved to PHP-Code.

Code: Select all

$to = "1";
$subject = "Report Post";

$result = mysql_query("INSERT INTO pm_box (`to`, `from`, `subject`, `message`, `date`) VALUES('$to', '$user_input', '$subject', '$message', '$date')")
or die(mysql_error());
I believe date is a reserved word.. you should quote your column names.
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

now it just give me this

Code: Select all

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', 'from', 'subject', 'message', 'date') VALUES('1', 'Jr', '
bobsta63
Forum Commoner
Posts: 28
Joined: Thu Apr 21, 2005 7:03 pm
Location: Ipswich, UK

Post by bobsta63 »

Jr wrote:now it just give me this

Code: Select all

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', 'from', 'subject', 'message', 'date') VALUES('1', 'Jr', '
I have had a problem like that before, I changed the field names in the database and it worked fine. I know it sounds weird, but I reckon on of the to, from, subject, message or date is already used as an internal function, If you know what i mean :?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Jr wrote:now it just give me this

Code: Select all

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', 'from', 'subject', 'message', 'date') VALUES('1', 'Jr', '
Sorry my reply was incomplete. Try changing your column names.
also wouldnt hurt to read http://dev.mysql.com/doc/mysql/en/maxdb ... words.html
Jr
Forum Commoner
Posts: 99
Joined: Mon Mar 07, 2005 3:25 pm

Post by Jr »

yeah that was the problem... thanks for the help
bobsta63
Forum Commoner
Posts: 28
Joined: Thu Apr 21, 2005 7:03 pm
Location: Ipswich, UK

Post by bobsta63 »

What was the problem, Globals or Change the database field names?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

As I said before, he was using reserved words.
bobsta63
Forum Commoner
Posts: 28
Joined: Thu Apr 21, 2005 7:03 pm
Location: Ipswich, UK

Post by bobsta63 »

O, Cool, How do you find out what words are reserved by MySQL? Is their a list, I suppose I would find that on the MySQL site :)
bobsta63
Forum Commoner
Posts: 28
Joined: Thu Apr 21, 2005 7:03 pm
Location: Ipswich, UK

Post by bobsta63 »

Sorry I just found your link to reserved words. I understand :D
Post Reply