php mysql查询返回错误

时间:2014-11-16 15:56:08

标签: 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, 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麸质& amp;&amp ;;小麦免费经典白面包,14.1盎司(包','

< b> S'

     

错误1064(42000):您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在#< 1,0)附近使用正确的语法'

     

错误1064(42000):您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在' 0'

附近使用正确的语法

$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)值(' Schar麸质和小麦免费经典白面包,14.1盎司(包',' 030684927201','',1000, 6,0,1,36.26,0,0,' 2014-11-16',9.0,11,45,45,45,45,1,1,1,1,0,&#39 ; 2014-11-16 02:23:37' 2014-11-16 02:23:37');

     

插入oc_product_to_category(product_id,category_id)选择(从oc_product中选择product_id,其中model =' Schar麸质和小麦免费经典白面包,14.1盎司(包装'和价格= 36.26限制1), (从oc_category_description中选择category_id,其中name =' Bakery& Bread');

     

插入oc_product_description(product_id,language_id,name,description,tag,meta_title,meta_description,meta_keyword)(从oc_product中选择product_id,其中model =' Schar麸质和小麦免费经典白面包,14.1盎司(Pack& #39;和价格= 36.26限制1),1,' Schar麸质和小麦免费经典白面包,14.1盎司(包','

< b> ; Schar麸质和无麦经典白面包:< /< />< />低脂肪和饱和脂肪< / li>< / li>< / li>< / li>< />< />< />< /> / li>< li> No lactose< / li>< / ul>

''面包和面包' Schar麸质和小麦免费经典白面包,14.1盎司(包装'< b>< b>>>>><>< />< />< l>低脂肪和饱和脂肪< /< /> li>< li>不含麸质< / li>< li>小麦无< / li>< li>无乳糖< / li>< /< /< /< /< /< /< />< />< b> Schar麸质和小麦免费经典白面包:< / b>< ul>< li>低脂肪和饱和脂肪< / li>< li>不含麸质< / li>< li>小麦免费< / li>< li>否&乳糖LT; /立GT;< / UL>&#39 ;;

     

插入oc_product_reward(product_id,customer_group_id,points)(从oc_product中选择product_id,其中model =' Schar麸质和小麦免费经典白面包,14.1盎司(包装'和价格= 36.26限制1) ,1,0;

     

插入oc_product_to_store(product_id,store_id)(从oc_product中选择product_id,其中model =' Schar麸质和小麦免费经典白面包,14.1盎司(包装'价格= 36.26限制1),0 ;

2 个答案:

答案 0 :(得分:1)

  

$ string。="插入oc_product_reward   (product_id,customer_group_id,points)(从中选择product_id)   oc_product其中model =' $ name'和价格= $ 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;";