Jump to content

SQL query problem with php


eggy524

Recommended Posts

Hi, I'm creating a small shopping cart system with php and MySQL and need some help. I have a table in MySQL called 'order' with fields:

 

OrderID int(10) - SET AS PRIMAY KEY AND TO AUTO-INCREMENT

Username varchar(30)

OrderDate

Paid int(1)

DIspatched int(1)

 

I want to add a row to this table so in php I use this code:

 

$current_date = date('Y-m-d');

$sql = "INSERT INTO order (Username, OrderDate) VALUES ('$username' , '$current_date')";

$result = mysql_query($sql);

 

if(!$result)

{

  die(mysql_error());

}

else

{

  echo 'OK';

}

 

As far as i know, the fields below do not need to be inserted in my query because they have default values or otherwise:

 

OrderID - should automatically increment

Paid - Default value set to 1

Dispatched - Default value set to 0

 

The problem is that when i run this query I get the error message:

 

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 WHERE Username='test'' at line 1

 

I cant see anything wrong with this query, does anyone have any ideas?

 

Thanks, adamport

Link to comment
https://forums.phpfreaks.com/topic/40224-sql-query-problem-with-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.