php mysql查询返回错误
有人能发现这些行中的错误吗php mysql查询返回错误,php,mysql,Php,Mysql,有人能发现这些行中的错误吗 $string .= "insert into oc_product (model, upc, location, quantity, stock_status_id, manufacturer_id, shipping, price, points, tax_class_id, date_available, weight, weight_class_id, length, width, height, length_class_id, subtract,
$string .= "insert into oc_product (model, upc, location, quantity, stock_status_id, manufacturer_id, shipping, price, points, tax_class_id, date_available, weight, weight_class_id, length, width, height, length_class_id, subtract, minimum, sort_order, status, viewed, date_added, date_modified) values ('$name','$upc','',1000,6,0,1,$price, 0,0,'2014-11-16',9.0,11,45,45,45,45,1,1,1,1,0,'2014-11-16 02:23:37','2014-11-16 02:23:37');";
$string .= "insert into oc_product_to_category (product_id, category_id) select (select product_id from oc_product where model='$name' and price=$price limit 1), (select category_id from oc_category_description where name='$cats[$i]');";
$string .= "insert into oc_product_description (product_id,language_id,name,description,tag,meta_title,meta_description,meta_keyword) (select product_id from oc_product where model='$name' and price=$price limit 1),1,'$name','<p>$desc</p>','$cats[$i]','$name','$desc','$desc';";
$string .= "insert into oc_product_reward (product_id,customer_group_id,points) (select product_id from oc_product where model='$name' and price=$price limit 1),1,0);";
$string .= "insert into oc_product_to_store (product_id,store_id) (select product_id from oc_product where model='$name' and price=$price limit 1),0;";
以下是我的错误:
错误1064 42000:您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,了解可在“1”、“Schar麸质小麦免费经典白面包,14.1盎司包装”附近使用的正确语法
错误1064 42000:您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解在“1,0”附近使用的正确语法
错误1064 42000:您的SQL语法有错误;查看与MySQL服务器版本对应的手册,以了解在“0”附近使用的正确语法
$string的输出如下所示
插入oc_产品型号、upc、位置、数量、库存状态识别号、制造商识别号、发货、价格、积分、税务分类识别号、可用日期、重量、重量分类识别号、长度、宽度、高度、长度分类识别号、减法、最小值、排序顺序、状态、查看、添加日期、日期修改值“沙尔无麸质小麦经典白面包”,14.1盎司包装,'030684927201',1000,6,0,1,36.26,0,0,'2014-11-16',9.0,11,45,45,45,45,45,1,1,1,0,'2014-11-16 02:23:37','2014-11-16 02:23:37'
插入oc_product_至_category product_id,category_id从oc_product中选择product_id,型号:='Schar麸质和小麦免费经典白面包,14.1盎司包装',价格=36.26限制1,从oc_category_描述中选择category_id,名称:='Bakery&Bread'
插入oc_产品描述product_id、language_id、姓名、描述、标签、meta_title、meta_description、meta_关键字从oc_产品中选择product_id,其中model='Schar麸质和小麦免费经典白面包,14.1盎司包装'和price=36.26 limit 1,1,'Schar麸质和小麦免费经典白面包,14.1盎司包装',“Schar麸质和小麦免费经典白面包:低脂和饱和脂肪无麸质小麦免费乳糖”、“面包房和面包”、“Schar麸质和小麦免费经典白面包,14.1盎司包装”、“Schar麸质和小麦免费经典白面包:低脂和饱和脂肪无麸质小麦免费乳糖”,“沙尔面筋&无小麦经典白面包:低脂、饱和脂肪、无麸质、无小麦、无乳糖”
在oc_产品\奖励产品\ id、客户\群体\ id中插入积分,从oc_产品中选择产品\ id,型号:='Schar麸质和小麦免费经典白面包,14.1盎司包装',价格=36.26限值1,1,0
插入oc_product_to_store product_id,store_id从oc_product中选择product_id,型号为“Schar麸质和小麦免费经典白面包,14.1盎司包装”,价格=36.26限量1,0
$string.=插入oc\u产品\u奖励
产品id、客户组id、点从中选择产品id
oc_产品,其中型号为“$name”,价格为$price limit 1,1,0
这里有一个结束括号。看起来第三行、第四行和第五行是问题所在
$string .= "insert into oc_product_description (product_id,language_id,name,description,tag,meta_title,meta_description,meta_keyword) (select product_id from oc_product where model='$name' and price=$price limit 1),1,'$name','<p>$desc</p>','$cats[$i]','$name','$desc','$desc';";
$string .= "insert into oc_product_reward (product_id,customer_group_id,points) (select product_id from oc_product where model='$name' and price=$price limit 1),1,0);";
$string .= "insert into oc_product_to_store (product_id,store_id) (select product_id from oc_product where model='$name' and price=$price limit 1),0;";
上述查询具有这种模式
INSERT INTO tablename (...) (SELECT ... FROM ...),x,y,...
这对于插入语法无效。将查询更改为此模式
INSERT INTO tablename (...) SELECT ...,x,y,... FROM ....
如下
$string .= "insert into oc_product_description
(product_id,
language_id,
name,
description,
tag,
meta_title,
meta_description,
meta_keyword)
select
product_id,
1,
'".$name."',
'<p>$desc</p>',
'".$cats[$i]."',
'".$name."',
'".$desc."',
'".$desc."'
from oc_product
where model = '".$name."' and price = ".$price." limit 1;";
$string .= "insert into oc_product_reward
(product_id,
customer_group_id,
points)
select
product_id,
1,
0
from oc_product
where model = '".$name."' and price = ".$price." limit 1;";
$string .= "insert into oc_product_to_store
(product_id,
store_id)
select
product_id,
0
from oc_product
where model = '".$name."' and price = ".$price." limit 1;";
请给我们$string的输出。echo$字符串;为什么要标记SQL SERVER???我删除了额外的括号,但仍然得到相同的错误删除;我希望这会有帮助you@Voltron我建议你单独测试你陈述的每一行。在如此庞大的查询中很难找出问题所在。然后在错误再次出现的地方张贴这一行。只需一个小的输入,就应该转义变量$string=foo$var。酒吧谢谢@S.Visser的输入,我已经更新了我的答案。