Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2010

    Unanswered: Problem in Insert with On Duplicate Key Update


    I have code for importing data from .xml file to database.

    My issue is the On Dupliicate Key Update did not work, ti save again the data even the data is already exist..

    here is my code:

    $sql = "INSERT INTO sales_order (ProductType,WorkOrder,POIssueDate,SalesMonth) 
          ProductType = '$ProductType', WorkOrder = '$WorkOrder', POIssueDate = '$POIssueDate', SalesMonth = '$SalesMonth'" or die(mysql_error());
    For example I attach file then I attahc again but I update some data I want it to update on database if the ProductType is already exist and add if not.

    I attach my sample upload file. and You can see on the second upload the ProductType P101 change the sales month.

    In my query the data that was second upload was insert again it did not update the existing data.I want the result should be the second upload not mix the first and second upload. Now the data was duplicated, thats my problem. I want it to update if the ProductType is already exist.

    Thank you
    Attached Thumbnails Attached Thumbnails SalesOrderFirstUpload.jpg   SalesOrderSecondUpload.jpg  

  2. #2
    Join Date
    Sep 2009
    San Sebastian, Spain
    Are you sure you have the correct unique index or primary key setup on the table?
    Ronan Cashell
    Certified Oracle DBA/Certified MySQL Expert (DBA & Cluster DBA)
    Follow me on Twitter

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts