SQL Error?

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
Paws
Forum Newbie
Posts: 15
Joined: Sun Nov 30, 2008 8:26 am

SQL Error?

Post by Paws »

Hey, I am having trouble with the following sql query...

Code: Select all

$query = mysql_query("INSERT INTO `orders` (`order_status`,`productcode` ,`dispatch_date` ,`customer_id`) VALUES ('Ordered', '$item', '$date', '$email'") or trigger_error(mysql_error());
I am getting the error...
Notice: 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 '' at line 1 in /home/spadean1/public_html/john/order.php on line 46
Any help appreciated.

Thanks
aravona
Forum Contributor
Posts: 347
Joined: Sat Jun 13, 2009 3:59 pm
Location: England

Re: SQL Error?

Post by aravona »

`orders` should be orders, you dont need quotes around your table name.

http://www.w3schools.com/SQl/sql_insert.asp
User avatar
SimpleManWeb
Forum Commoner
Posts: 57
Joined: Wed Dec 30, 2009 4:15 pm
Location: New Hampshire, USA

Re: SQL Error?

Post by SimpleManWeb »

I don't see anything wrong with that sql statement. Have you tried executing this query directly into your database using phpmyadmin? You may get more detailed information about the error there.
`orders` should be orders, you dont need quotes around your table name.
Although the "`" around the table name is not necessary, it is not an error. In fact, many people will tell you that it's good programming practices to always use the table name in "`". It is very helpful when doing large sql statements.

Hope this helps
Post Reply