Adding data to database problem

Hi,

I am using


function add_content($p) {
		$productid = mysql_real_escape_string($p['productid']);
		$categoryid = mysql_real_escape_string($p['categoryid']);
		$name = mysql_real_escape_string($p['name']);
		$order = mysql_real_escape_string($p['order']);
		$price = mysql_real_escape_string($p['price']);
	
	$sql = "INSERT INTO products (id, productid, categoryid, name, order) VALUES (null, '$productid', '$categoryid', '$name', '$order')";
	$res = mysql_query($sql) or die(mysql_error());
	
	}
}

The problem is, as you can see I am adding:
id
productid
categoryid
name
order

The error I get is:

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 (null, ‘1’, ‘2’, ‘3’, ‘4’)’ at line 1

If I only add:
id
productid
categoryid
name

(ie. not including order)

then it works.

Also if I add ‘price’ instead of ‘order’ it works.

So it seems to me the problem is with the field ‘order’ but I am adding this field like the others I have done.

May be you know why I get the error above when adding this field???

Matt

You need to put marks aroundorder` because it is a reserved keyword in MySQL. Its a backtick - top left of the keyboard, next to 1. eg:

    $sql = "INSERT INTO products (id, productid, categoryid, name, `order`) VALUES (null, '$productid', '$categoryid', '$name', '$order')";

order is a reserved word in mysql
change it in something else (orderid for example) or put backticks around it.