Insert query is not working in my php file

I am getting values from a csv file and inserting them into my sql tables. I am trying to insert(or replace). It is not working. But when i use update query it works just fine and updates values correctly. I am not sure what is wrong in my script.

$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 );

But using the same values my update query works perfect. Can anyone see what i am doing wrong here??

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);  

I must mention that the product that i am entering is not in the table and the product that i am updating is in the system. So that i have already tested.

Answers


Online_only isn't quoted properly


For primary key that is id_supplier you are providing a value as $ID instead give a empty value as follows

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);

As Primary key is an autoincrement it will increment automatically


Need Your Help

Bash Script Linux print html Tags end

linux html5 bash shell

I have a bash script and it include 2 variables, and like to print this on html, but the problem it just work the open tag and no the ending or closing tag:

Avoiding multiple "@media" when using Bootstrap 3 less mixins

css twitter-bootstrap less mixins

When using less mixins to build a Website with Bootstrap I do something like this: