Page 1 of 1

SQL insert statement not working

Posted: Mon Nov 09, 2009 8:25 pm
by moneyshotkid
I have no idea why this insert statement is not working. I even tried using the statement directly from phpmyadmin and its still not working. I'm thinking its something terribly stupid. variables are cleared using addslashes(); and mysql_escape_string(); for the content variable Thanks in advance.

Sql Insert String:
$sql="INSERT INTO users(id,email,from,subject,content,cat1,cat2,cat3,active,username,password)VALUES(NULL,'$email','$from','$content','$subject','$cat1','$cat2','$cat3',$active,'$username','$password')";

Below is the $sql echo'ed out into the browser:
INSERT INTO users(id,email,from,subject,content,cat1,cat2,cat3,active,username,password)VALUES(NULL,'its@nicknguyen.com','Nicholas N','Hi Thank You in Advance for your time.\r\nNick N\r\nIts@NickNguyen.com\r\n\r\nhttp://www.NickNguyen.com','Subject of email','cpg','crg','cps',0,'its.nicknguyen@mail.com','password')

Error Message from mysql_error():
Invalid query: 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 'from,subject,content,cat1,cat2,cat3,active,username,password)VALUES(NULL,'its@ni' at line 1

Re: SQL insert statement not working

Posted: Mon Nov 09, 2009 8:47 pm
by McInfo
FROM is a reserved word in SQL. Identify it as a field name using backticks (`) or change the name of the field.

Edit: This post was recovered from search engine cache.

Re: SQL insert statement not working

Posted: Mon Nov 09, 2009 9:48 pm
by moneyshotkid
Damn I feel like such a noob. Thanks McInfo