SQL insert statement not working

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
moneyshotkid
Forum Newbie
Posts: 3
Joined: Mon Nov 09, 2009 8:14 pm

SQL insert statement not working

Post 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
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: SQL insert statement not working

Post 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.
Last edited by McInfo on Thu Jun 17, 2010 2:03 pm, edited 1 time in total.
moneyshotkid
Forum Newbie
Posts: 3
Joined: Mon Nov 09, 2009 8:14 pm

Re: SQL insert statement not working

Post by moneyshotkid »

Damn I feel like such a noob. Thanks McInfo
Post Reply