-1

I'm running this on my website:

$PlaceOrder = " Insert INTO Order VALUES ( '$CustomerID' , '$ItemID' , '$Quantity' , '$Date' ) ";   
    $result = mysql_query ($PlaceOrder);
    if (!$result)
    {
        die('Invalid query: ' . mysql_error());
    }

But when I ever I do I keep getting the following error message:

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 'Order VALUES ( '3' , '1' , '12' , '11/05/2013' )' at line 1

I really have no idea what to do now, I tried specifying the columns but that didn't work either. I am very new to this whole thing and I'm executing this based on whats in the manual.

bloodstorm17
  • 511
  • 1
  • 9
  • 25

4 Answers4

2

Let's look at your error message again:

[...] the right syntax to use near'OrderVALUES

The first thing it complains about is Order. That's what you substitute the Table from your question for. So let's assume that's your actual table name.

It's also a reserved word. Enclose reserved words in backticks when used as column or table name identifiers.

mario
  • 144,265
  • 20
  • 237
  • 291
0

Order is Key word Just use another word instead of Order

user2889058
  • 135
  • 4
  • 14
0

First of all, you should always specify the columns since you never know when you will have to add new columns to the table and old queries will start doing messy things if you haven't done that.

Having said that, are you sure those are the correct column data types that match the table's? Also, make sure the date format is valid, you shoud use Y-m-d. You will find more info here.

fos.alex
  • 5,317
  • 4
  • 16
  • 18
0

Are you sure there are only 4 columns and are they in the same order as you have specified in your query?

As you suggested try to add the column names, for example:

$PlaceOrder = "INSERT INTO Table (customer, item, quantity, date) VALUES ('$CustomerID', '$ItemID', '$Quantity', '$Date')";

Does this help you?

Arthur Borsboom
  • 323
  • 2
  • 10