Page 1 of 1
[SOLVED] what the HECK!!!
Posted: Fri Apr 22, 2005 2:37 pm
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
Posted: Fri Apr 22, 2005 2:51 pm
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.
Posted: Fri Apr 22, 2005 3:00 pm
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', '
Posted: Fri Apr 22, 2005 3:03 pm
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

Posted: Fri Apr 22, 2005 3:06 pm
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
Posted: Fri Apr 22, 2005 3:26 pm
by Jr
yeah that was the problem... thanks for the help
Posted: Fri Apr 22, 2005 3:40 pm
by bobsta63
What was the problem, Globals or Change the database field names?
Posted: Fri Apr 22, 2005 3:43 pm
by John Cartwright
As I said before, he was using reserved words.
Posted: Fri Apr 22, 2005 3:44 pm
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

Posted: Fri Apr 22, 2005 3:45 pm
by bobsta63
Sorry I just found your link to reserved words. I understand
