我刚刚开始使用PHP。我通过阅读和查看PHP上的内容进行自学,并且主要是剪切和粘贴片段以实现我的结果。但是,我熟悉HTML和JavaScript。
这是我的错误:
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 'group, category, subcategory, date_added, vendor) VALUES('ItemCode','NameofProdu' at line 1
我相信的代码会导致这个:
$sql = mysql_query("INSERT INTO products (part, product_name, units, cost, price, details, group, category, subcategory, date_added, vendor) VALUES('$part','$product_name','$units','$cost','$price','$details','$group','$category','$subcategory',now(),'$vendor')") or die (mysql_error());
$pid = mysql_insert_id();
看看MySQL表:
Field Type Null
id int(11) No
part varchar(11) No
product_name varchar(255) No
units int(11) No
cost varchar(16) No
price varchar(16) No
details text No
group varchar(32) No
category varchar(32) No
subcategory varchar(32) No
date_added date No
vendor varchar(32) No
我忽略了什么吗?
答案 0 :(得分:1)
更改字段名称group
或用引号括起来,它是mysql中的保留关键字。
答案 1 :(得分:0)
Group
是保留关键字,因此您应将列名称括在“
答案 2 :(得分:0)
你应该在组中使用返回刻度字符(`),例如:
$ sql = mysql_query(“INSERT INTO products(part,product_name,units,cost,price,details,group
,category,subcategory,date_added,vendor)VALUES('$ part','$ product_name' ,'$ units','$ cost','$ price','$ details','$ group','$ category','$ subcategory',now(),'$ vendor')“)或die( mysql_error());
$ pid = mysql_insert_id();
答案 3 :(得分:0)
mysql_query("INSERT INTO products (part, product_name, units, cost, price, details, `group`, category, subcategory, date_added, vendor) VALUES('$part','$product_name','$units','$cost','$price','$details','$group','$category','$subcategory',now(),'$vendor')") or die (mysql_error());