我从csv文件中获取值并将它们插入到我的sql表中 我想插入(或替换)。它不起作用。但是,当我使用更新查询时,它工作正常,并正确更新值 我不确定我的剧本有什么问题。
$query_insert = "
INSERT INTO
`ps_product`
(
`id_product`
,`id_supplier`
,`id_manufacturer`
,`id_category_default`
,`id_shop_default`
,`id_tax_rules_group`
,`on_sale`
,`online_only`
,`ean13`
,`upc`
,`ecotax`
,`quantity`
,`minimal_quantity`
,`price`
,`wholesale_price`
,`unity`
,`unit_price_ratio`
,`additional_shipping_cost`
,`reference`
,`supplier_reference`
,`location`
,`width`
,`height`
,`depth`
,`weight`
,`out_of_stock`
,`quantity_discount`
,`customizable`
,`uploadable_files`
,`text_fields`
,`active`
,`redirect_type`
,`id_product_redirected`
,`available_for_order`
,`available_date`
,`condition`
,`show_price`
,`indexed`
,`visibility`
,`cache_is_pack`
,`cache_has_attachments`
,`is_virtual`
,`cache_default_attribute`
,`date_add`
,`date_upd`
,`advanced_stock_management`
)
VALUES
(
" .$ID ."
,'2'
,'" .$id_manu ."'
,'" .$categoryRec ."'
,'2'
,'2'
,'0'
,'0'
,'" .$EAN ."'
,'" .$UPC ."'
,'0.000000'
,'0'
,'1'
,'" .$retailp ."'
,'" .$wholesalep ."'
,''
,'0.000000'
,'0.00'
,'" .$ref ."'
,'" .$ID ."'
,''
,'0.000000'
,'0.000000'
,'0.000000'
,'0.000000'
,'2'
,'0'
,'0'
,'0'
,'0'
,'1'
,''
,'0'
,'1'
,'0000-00-00'
,'new'
,'1'
,'1'
,'both'
,'0'
,'0'
,'0'
,'0'
,'" .$dateadded ."'
,'" .$dateupdated ."'
,'0'
)
";
// echo $query_insert;
mysql_query( $query_insert ,$conn );
但是使用相同的值我的更新查询是完美的。谁能看到我在这里做错了什么?
mysql_query("UPDATE `ps_product` SET `id_supplier`=1,`id_manufacturer`=$id_manu,`id_category_default`=$categoryRec,`id_shop_default`=1,`id_tax_rules_group`=1,`on_sale`=0,`online_only`=0,`ean13`='$EAN',`upc`='$UPC',`ecotax`=0.000000,`quantity`=0,`minimal_quantity`=1,`price`='$retailp',`wholesale_price`='$wholesalep',`unity`='',`unit_price_ratio`=0.000000,`additional_shipping_cost`=0.00,`reference`='$ref',`supplier_reference`=$ID,`location`='',`width`=0.000000,`height`=0.000000,`depth`=0.000000,`weight`=0.000000,`out_of_stock`=2,`quantity_discount`=0,`customizable`=0,`uploadable_files`=0,`text_fields`=0,`active`=1,`redirect_type`='',`id_product_redirected`=0,`available_for_order`=1,`available_date`='0000-00-00',`condition`='new',`show_price`=1,`indexed`=1,`visibility`='both',`cache_is_pack`=0,`cache_has_attachments`=0,`is_virtual`=0,`cache_default_attribute`=0,`date_add`='$dateadded',`date_upd`='$dateupdated',`advanced_stock_management`=0 WHERE `id_product`=$ID",$conn);
我必须提到我输入的产品不在表格中,我正在更新的产品在系统中。所以我已经测试了。
答案 0 :(得分:1)
Online_only未正确引用
答案 1 :(得分:0)
对于id_supplier的主键,您提供的值为$ ID,而不是按如下方式提供空值
mysql_query("INSERT INTO `ps_product` (`id_product`,`id_supplier`,`id_manufacturer`,`id_category_default`,`id_shop_default`,`id_tax_rules_group`,`on_sale,online_only`,`ean13`,`upc`,`ecotax`,`quantity`,`minimal_quantity`,`price`,`wholesale_price`,`unity`,`unit_price_ratio`,`additional_shipping_cost`,`reference`,`supplier_reference`,`location`,`width`,`height`,`depth`,`weight`,`out_of_stock`,`quantity_discount`,`customizable`,`uploadable_files`,`text_fields`,`active`,`redirect_type`,`id_product_redirected`,`available_for_order`,`available_date`,`condition`,`show_price`,`indexed`,`visibility`,`cache_is_pack`,`cache_has_attachments`,`is_virtual`,`cache_default_attribute`,`date_add`,`date_upd`,`advanced_stock_management`) VALUES ('',2,$id_manu,$categoryRec,2,2,0,0,'$EAN','$UPC',0.000000,0,1,'$retailp','$wholesalep','',0.000000,0.00,'$ref',$ID,'',0.000000,0.000000,0.000000,0.000000,2,0,0,0,0,1,'',0,1,'0000-00-00','new',1,1,'both',0,0,0,0,'$dateadded','$dateupdated',0)",$conn);
由于主键是自动增量,它会自动增加