有人能发现这些行中的错误吗?
$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;&#39; Schar麸质&amp; amp;&amp ;;小麦免费经典白面包,14.1盎司(包&#39;,&#39;
&lt; b&gt; S&#39;
错误1064(42000):您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在#&lt; 1,0)附近使用正确的语法&#39;
错误1064(42000):您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在&#39; 0&#39;
附近使用正确的语法
$string
的输出低于
插入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)值(&#39; Schar麸质和小麦免费经典白面包,14.1盎司(包&#39;,&#39; 030684927201&#39;,&#39;&#39;,1000, 6,0,1,36.26,0,0,&#39; 2014-11-16&#39;,9.0,11,45,45,45,45,1,1,1,1,0,&#39 ; 2014-11-16 02:23:37&#39; 2014-11-16 02:23:37&#39;);
插入oc_product_to_category(product_id,category_id)选择(从oc_product中选择product_id,其中model =&#39; Schar麸质和小麦免费经典白面包,14.1盎司(包装&#39;和价格= 36.26限制1), (从oc_category_description中选择category_id,其中name =&#39; Bakery&amp; Bread&#39;);
插入oc_product_description(product_id,language_id,name,description,tag,meta_title,meta_description,meta_keyword)(从oc_product中选择product_id,其中model =&#39; Schar麸质和小麦免费经典白面包,14.1盎司(Pack& #39;和价格= 36.26限制1),1,&#39; Schar麸质和小麦免费经典白面包,14.1盎司(包&#39;,&#39;
&lt; b&gt; ; Schar麸质和无麦经典白面包:&lt; /&lt; /&gt;&lt; /&gt;低脂肪和饱和脂肪&lt; / li&gt;&lt; / li&gt;&lt; / li&gt;&lt; / li&gt;&lt; /&gt;&lt; /&gt;&lt; /&gt;&lt; /&gt; / li&gt;&lt; li&gt; No lactose&lt; / li&gt;&lt; / ul&gt;
&#39;&#39;面包和面包&#39; Schar麸质和小麦免费经典白面包,14.1盎司(包装&#39;&lt; b&gt;&lt; b&gt;&gt;&gt;&gt;&gt;&lt;&gt;&lt; /&gt;&lt; /&gt;&lt; l&gt;低脂肪和饱和脂肪&lt; /&lt; /&gt; li&gt;&lt; li&gt;不含麸质&lt; / li&gt;&lt; li&gt;小麦无&lt; / li&gt;&lt; li&gt;无乳糖&lt; / li&gt;&lt; /&lt; /&lt; /&lt; /&lt; /&lt; /&lt; /&gt;&lt; /&gt;&lt; b&gt; Schar麸质和小麦免费经典白面包:&lt; / b&gt;&lt; ul&gt;&lt; li&gt;低脂肪和饱和脂肪&lt; / li&gt;&lt; li&gt;不含麸质&lt; / li&gt;&lt; li&gt;小麦免费&lt; / li&gt;&lt; li&gt;否&乳糖LT; /立GT;&LT; / UL&GT;&#39 ;;
插入oc_product_reward(product_id,customer_group_id,points)(从oc_product中选择product_id,其中model =&#39; Schar麸质和小麦免费经典白面包,14.1盎司(包装&#39;和价格= 36.26限制1) ,1,0;
插入oc_product_to_store(product_id,store_id)(从oc_product中选择product_id,其中model =&#39; Schar麸质和小麦免费经典白面包,14.1盎司(包装&#39;价格= 36.26限制1),0 ;
答案 0 :(得分:1)
$ string。=&#34;插入oc_product_reward (product_id,customer_group_id,points)(从中选择product_id) oc_product其中model =&#39; $ name&#39;和价格= $ price limit 1),1,0);&#34 ;;
有一个结束括号。
答案 1 :(得分:1)
看起来第三,第四和第五行是问题
$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;";