Jump to content

Problem in Insert with On Duplicate Key Update


newphpcoder

Recommended Posts

Hi..

 

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) 
      VALUES 
      ('$ProductType','$WorkOrder','$POIssueDate','$SalesMonth')
      ON DUPLICATE KEY UPDATE
      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

post-101569-13482403403104_thumb.jpg

post-101569-13482403426324_thumb.jpg

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.