0

I get this error:

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 'order (total, addy, cc) VALUES ('798' , '123 sadf' , '12124123')' at line 1

$total = addslashes(($_SESSION['total']));

$addy = addslashes(($_POST['addy']));

$cc = addslashes(($_POST['cc']));

echo "$total";

echo "$addy";

echo "$cc";

mysql_query("INSERT INTO order (total, addy, cc) VALUES ('$total' , '$addy' , '$cc')") or die(mysql_error());

How can I fix this problem?

1
  • Don't use any keyword or reserve name as field or table name. Rename the order. Commented May 26, 2010 at 5:16

4 Answers 4

7

In SQL order is a reserved word. Instead use:

INSERT INTO `order`
Sign up to request clarification or add additional context in comments.

Comments

3

The reason why this is failing is because "order" is a keyword in SQL.

You need to put backticks around table names to avoid problems like these.

Comments

2

Try putting ticks around order

`order`

Comments

-3

You forgot "$connection"

mysql_query("INSERT INTO order (total, addy, cc) VALUES ('$total' , '$addy' , '$cc')",$connection) or die(mysql_error());

1 Comment

Col. Shrapnel is correct. The fact that he is getting a MySQL error shows that the connection is already established. The mysql_query() function uses an already established connection by default if one is not specified. The connection is not an issue. Read the manual -> us2.php.net/manual/en/function.mysql-query.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.