SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    On duplicate key Update did not work

    Hi..

    I encountered problem in using on duplicate key update..


    here is my query:

    Code:
    INSERT INTO parameter_settings 
        (P27, P27_max, P27LOT_max, P27_maxdoz, P27Doz_max, P27_min, P27LOT_min, P27_mindoz, P27Doz_min,
         P28, P28_max, P28LOT_max, P28_maxdoz, P28Doz_max, P28_min, P28LOT_min, P28_mindoz, P28Doz_min,
         P30, P30_max, P30LOT_max, P30_maxdoz, P30Doz_max, P30_min, P30LOT_min, P30_mindoz, P30Doz_min,
         P32, P32_max, P32LOT_max, P32_maxdoz, P32Doz_max, P32_min, P32LOT_min, P32_mindoz, P32Doz_min,
         P32W, P32W_max, P32WLOT_max, P32W_maxdoz, P32WDoz_max, P32W_min, P32WLOT_min, P32W_mindoz, P32WDoz_min,
         P33, P33_max, P33LOT_max, P33_maxdoz, P33Doz_max, P33_min, P33LOT_min, P33_mindoz, P33Doz_min, 
         P35, P35_max, P35LOT_max, P35_maxdoz, P35Doz_max, P35_min, P35LOT_min, P35_mindoz, P35Doz_min,
         P35M, P35M_max, P35MLOT_max, P35M_maxdoz, P35MDoz_max, P35M_min, P35MLOT_min, P35M_mindoz, P35MDoz_min,
         P35W, P35W_max, P35WLOT_max, P35W_maxdoz, P35WDoz_max, P35W_min, P35WLOT_min, P35W_mindoz, P35WDoz_min,
         P38, P38_max, P38LOT_max, P38_maxdoz, P38Doz_max, P38_min, P38LOT_min, P38_mindoz, P38Doz_min,
         P41, P41_max, P41LOT_max, P41_maxdoz, P41Doz_max, P41_min, P41LOT_min, P41_mindoz, P41Doz_min,
         P42, P42_max, P42LOT_max, P42_maxdoz, P42Doz_max, P42_min, P42LOT_min, P42_mindoz, P42Doz_min,
         P43, P43_max, P43LOT_max, P43_maxdoz, P43Doz_max, P43_min, P43LOT_min, P43_mindoz, P43Doz_min,
         P45, P45_max, P45LOT_max, P45_maxdoz, P45Doz_max, P45_min, P45LOT_min, P45_mindoz, P45Doz_min,
         P46, P46_max, P46LOT_max, P46_maxdoz, P46Doz_max, P46_min, P46LOT_min, P46_mindoz, P46Doz_min,
         P47, P47_max, P47LOT_max, P47_maxdoz, P47Doz_max, P47_min, P47LOT_min, P47_mindoz, P47Doz_min,
         Total, Total_max, TotalLOT_max, Total_maxdoz, TotalDoz_max, Total_min, TotalLOT_min, Total_mindoz, TotalDoz_min
         ) 
        VALUES 
        ('$P27', '$P27_max', '$P27LOT_max', '$P27_maxdoz', '$P27Doz_max', '$P27_min', '$P27LOT_min', '$P27_mindoz', '$P27Doz_min',
         '$P28', '$P28_max', '$P28LOT_max', '$P28_maxdoz', '$P28Doz_max', '$P28_min', '$P28LOT_min', '$P28_mindoz', '$P28Doz_min',
         '$P30', '$P30_max', '$P30LOT_max', '$P30_maxdoz', '$P30Doz_max', '$P30_min', '$P30LOT_min', '$P30_mindoz', '$P30Doz_min',
         '$P32', '$P32_max', '$P32LOT_max', '$P32_maxdoz', '$P32Doz_max', '$P32_min', '$P32LOT_min', '$P32_mindoz', '$P32Doz_min',
         '$P32W', '$P32W_max', '$P32WLOT_max', '$P32W_maxdoz', '$P32WDoz_max', '$P32W_min', '$P32WLOT_min', '$P32W_mindoz', '$P32WDoz_min',
         '$P33', '$P33_max', '$P33LOT_max', '$P33_maxdoz', '$P33Doz_max', '$P33_min', '$P33LOT_min', '$P33_mindoz', '$P33Doz_min',
         '$P35', '$P35_max', '$P35LOT_max', '$P35_maxdoz', '$P35Doz_max', '$P35_min', '$P35LOT_min', '$P35_mindoz', '$P35Doz_min',
         '$P35M', '$P35M_max', '$P35MLOT_max', '$P35M_maxdoz', '$P35MDoz_max', '$P35M_min', '$P35MLOT_min', '$P35M_mindoz', '$P35MDoz_min',
         '$P35W', '$P35W_max', '$P35WLOT_max', '$P35W_maxdoz', '$P35WDoz_max', '$P35W_min', '$P35WLOT_min', '$P35W_mindoz', '$P35WDoz_min',
         '$P38', '$P38_max', '$P38LOT_max', '$P38_maxdoz', '$P38Doz_max', '$P38_min', '$P38LOT_min', '$P38_mindoz', '$P38Doz_min',
         '$P41', '$P41_max', '$P41LOT_max', '$P41_maxdoz', '$P41Doz_max', '$P41_min', '$P41LOT_min', '$P41_mindoz', '$P41Doz_min', 
         '$P42', '$P42_max', '$P42LOT_max', '$P42_maxdoz', '$P42Doz_max', '$P42_min', '$P42LOT_min', '$P42_mindoz', '$P42Doz_min',
         '$P43', '$P43_max', '$P43LOT_max', '$P43_maxdoz', '$P43Doz_max', '$P43_min', '$P43LOT_min', '$P43_mindoz', '$P43Doz_min',
         '$P45', '$P45_max', '$P45LOT_max', '$P45_maxdoz', '$P45Doz_max', '$P45_min', '$P45LOT_min', '$P45_mindoz', '$P45Doz_min',
         '$P46', '$P46_max', '$P46LOT_max', '$P46_maxdoz', '$P46Doz_max', '$P46_min', '$P46LOT_min', '$P46_mindoz', '$P46Doz_min',
         '$P47', '$P47_max', '$P47LOT_max', '$P47_maxdoz', '$P47Doz_max', '$P47_min', '$P47LOT_min', '$P47_mindoz', '$P47Doz_min',
         '$Total', '$Total_max', '$TotalLOT_max', '$Total_maxdoz', '$TotalDoz_max', '$Total_min', '$TotalLOT_min', '$Total_mindoz', '$TotalDoz_min'     
        )
        ON DUPLICATE KEY UPDATE                                                                                                      
        P27 = '$P27', P27_max = '$P27_max', P27LOT_max = '$P27LOT_max', P27_maxdoz = '$P27_maxdoz', P27Doz_max = '$P27Doz_max',
        P27_min = '$P27_min', P27LOT_min = '$P27LOT_min', P27_mindoz = '$P27_mindoz', P27Doz_min = '$P27Doz_min',
        P28 = '$P28', P28_max = '$P28_max', P28LOT_max = '$P28LOT_max', P28_maxdoz = '$P28_maxdoz', P28Doz_max = '$P28Doz_max',
        P28_min = '$P28_min', P28LOT_min = '$P28LOT_min', P28_mindoz = '$P28_mindoz', P28Doz_min = '$P28Doz_min',
        P30 = '$P30', P30_max = '$P30_max', P30LOT_max = '$P30LOT_max', P30_maxdoz = '$P30_maxdoz', P30Doz_max = '$P30Doz_max',
        P30_min = '$P30_min', P30LOT_min = '$P30LOT_min', P30_mindoz = '$P30_mindoz', P30Doz_min = '$P30Doz_min',
        P32 = '$P32', P32_max = '$P32_max', P32LOT_max = '$P32LOT_max', P32_maxdoz = '$P32_maxdoz', P32Doz_max = '$P32Doz_max',
        P32_min = '$P32_min', P32LOT_min = '$P32LOT_min', P32_mindoz = '$P32_mindoz', P32Doz_min = '$P32Doz_min',
        P32W = '$P32W', P32W_max = '$P32W_max', P32WLOT_max = '$P32WLOT_max', P32W_maxdoz = '$P32W_maxdoz', P32WDoz_max = '$P32WDoz_max',
        P32W_min = '$P32W_min', P32WLOT_min = '$P32WLOT_min', P32W_mindoz = '$P32W_mindoz', P32WDoz_min = '$P32WDoz_min',
        P33 = '$P33', P33_max = '$P33_max', P33LOT_max = '$P33LOT_max', P33_maxdoz = '$P33_maxdoz', P33Doz_max = '$P33Doz_max',
        P33_min = '$P33_min', P33LOT_min = '$P33LOT_min', P33_mindoz = '$P33_mindoz', P33Doz_min = '$P33Doz_min',
        P35 = '$P35', P35_max = '$P35_max', P35LOT_max = '$P35LOT_max', P35_maxdoz = '$P35_maxdoz', P35Doz_max = '$P35Doz_max',
        P35_min = '$P35_min', P35LOT_min = '$P35LOT_min', P35_mindoz = '$P35_mindoz', P35Doz_min = '$P35Doz_min',
        P35M = '$P35M', P35M_max = '$P35M_max', P35MLOT_max = '$P35MLOT_max', P35M_maxdoz = '$P35M_maxdoz', P35MDoz_max = '$P35MDoz_max',
        P35M_min = '$P35M_min', P35MLOT_min = '$P35MLOT_min', P35M_mindoz = '$P35M_mindoz', P35MDoz_min = '$P35MDoz_min',
        P35W = '$P35W', P35W_max = '$P35W_max', P35WLOT_max = '$P35WLOT_max', P35W_maxdoz = '$P35W_maxdoz', P35WDoz_max = '$P35WDoz_max',
        P35W_min = '$P35W_min', P35WLOT_min = '$P35WLOT_min', P35W_mindoz = '$P35W_mindoz', P35WDoz_min = '$P35WDoz_min',
        P38 = '$P38', P38_max = '$P38_max', P38LOT_max = '$P38LOT_max', P38_maxdoz = '$P38_maxdoz', P38Doz_max = '$P38Doz_max',
        P38_min = '$P38_min', P38LOT_min = '$P38LOT_min', P38_mindoz = '$P38_mindoz', P38Doz_min = '$P38Doz_min',
        P41 = '$P41', P41_max = '$P41_max', P41LOT_max = '$P41LOT_max', P41_maxdoz = '$P41_maxdoz', P41Doz_max = '$P41Doz_max',
        P41_min = '$P41_min', P41LOT_min = '$P41LOT_min', P41_mindoz = '$P41_mindoz', P41Doz_min = '$P41Doz_min',
        P42 = '$P42', P42_max = '$P42_max', P42LOT_max = '$P42LOT_max', P42_maxdoz = '$P42_maxdoz', P42Doz_max = '$P42Doz_max',
        P42_min = '$P42_min', P42LOT_min = '$P42LOT_min', P42_mindoz = '$P42_mindoz', P42Doz_min = '$P42Doz_min',
        P43 = '$P43', P43_max = '$P43_max', P43LOT_max = '$P43LOT_max', P43_maxdoz = '$P43_maxdoz', P43Doz_max = '$P43Doz_max',
        P43_min = '$P43_min', P43LOT_min = '$P43LOT_min', P43_mindoz = '$P43_mindoz', P43Doz_min = '$P43Doz_min',
        P45 = '$P45', P45_max = '$P45_max', P45LOT_max = '$P45LOT_max', P45_maxdoz = '$P45_maxdoz', P45Doz_max = '$P45Doz_max',
        P45_min = '$P45_min', P45LOT_min = '$P45LOT_min', P45_mindoz = '$P45_mindoz', P45Doz_min = '$P45Doz_min',
        P46 = '$P46', P46_max = '$P46_max', P46LOT_max = '$P46LOT_max', P46_maxdoz = '$P46_maxdoz', P46Doz_max = '$P46Doz_max',
        P46_min = '$P46_min', P46LOT_min = '$P46LOT_min', P46_mindoz = '$P46_mindoz', P46Doz_min = '$P46Doz_min',
        P47 = '$P47', P47_max = '$P47_max', P47LOT_max = '$P47LOT_max', P47_maxdoz = '$P47_maxdoz', P47Doz_max = '$P47Doz_max',
        P47_min = '$P47_min', P47LOT_min = '$P47LOT_min', P47_mindoz = '$P47_mindoz', P47Doz_min = '$P47Doz_min',
        Total = '$Total', Total_max = '$Total_max', TotalLOT_max = '$TotalLOT_max', Total_maxdoz = '$Total_maxdoz', TotalDoz_max = '$TotalDoz_max',
        Total_min = '$Total_min', TotalLOT_min = '$TotalLOT_min', Total_mindoz = '$Total_mindoz', TotalDoz_min = '$TotalDoz_min'
    I want to happen is only one row will add in my database and if I need to edit my data It will update the data that already been save. But in my code instead of updating my data in my database, it will insert or again in another row.

    I canít figure out whatís wrong or missing in my query syntax. Thank you

    Thank you

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    It will do the update only if it encounters a duplicate key. If it does the insert, it means there is no duplicate key.
    Check the unique keys you've set for that table, and the values present in the table. Is the new key value you are inserting already present in the table?

  3. #3
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I add Ref_Num as unique.

    Code:
    INSERT INTO parameter_settings 
        (Ref_Num, P27, P27_max, P27LOT_max, P27_maxdoz, P27Doz_max, P27_min, P27LOT_min, P27_mindoz, P27Doz_min,
         P28, P28_max, P28LOT_max, P28_maxdoz, P28Doz_max, P28_min, P28LOT_min, P28_mindoz, P28Doz_min,
         P30, P30_max, P30LOT_max, P30_maxdoz, P30Doz_max, P30_min, P30LOT_min, P30_mindoz, P30Doz_min,
         P32, P32_max, P32LOT_max, P32_maxdoz, P32Doz_max, P32_min, P32LOT_min, P32_mindoz, P32Doz_min,
         P32W, P32W_max, P32WLOT_max, P32W_maxdoz, P32WDoz_max, P32W_min, P32WLOT_min, P32W_mindoz, P32WDoz_min,
         P33, P33_max, P33LOT_max, P33_maxdoz, P33Doz_max, P33_min, P33LOT_min, P33_mindoz, P33Doz_min, 
         P35, P35_max, P35LOT_max, P35_maxdoz, P35Doz_max, P35_min, P35LOT_min, P35_mindoz, P35Doz_min,
         P35M, P35M_max, P35MLOT_max, P35M_maxdoz, P35MDoz_max, P35M_min, P35MLOT_min, P35M_mindoz, P35MDoz_min,
         P35W, P35W_max, P35WLOT_max, P35W_maxdoz, P35WDoz_max, P35W_min, P35WLOT_min, P35W_mindoz, P35WDoz_min,
         P38, P38_max, P38LOT_max, P38_maxdoz, P38Doz_max, P38_min, P38LOT_min, P38_mindoz, P38Doz_min,
         P41, P41_max, P41LOT_max, P41_maxdoz, P41Doz_max, P41_min, P41LOT_min, P41_mindoz, P41Doz_min,
         P42, P42_max, P42LOT_max, P42_maxdoz, P42Doz_max, P42_min, P42LOT_min, P42_mindoz, P42Doz_min,
         P43, P43_max, P43LOT_max, P43_maxdoz, P43Doz_max, P43_min, P43LOT_min, P43_mindoz, P43Doz_min,
         P45, P45_max, P45LOT_max, P45_maxdoz, P45Doz_max, P45_min, P45LOT_min, P45_mindoz, P45Doz_min,
         P46, P46_max, P46LOT_max, P46_maxdoz, P46Doz_max, P46_min, P46LOT_min, P46_mindoz, P46Doz_min,
         P47, P47_max, P47LOT_max, P47_maxdoz, P47Doz_max, P47_min, P47LOT_min, P47_mindoz, P47Doz_min,
         Total, Total_max, TotalLOT_max, Total_maxdoz, TotalDoz_max, Total_min, TotalLOT_min, Total_mindoz, TotalDoz_min
         ) 
        VALUES 
        ('$RefNum', '$P27', '$P27_max', '$P27LOT_max', '$P27_maxdoz', '$P27Doz_max', '$P27_min', '$P27LOT_min', '$P27_mindoz', '$P27Doz_min',
         '$P28', '$P28_max', '$P28LOT_max', '$P28_maxdoz', '$P28Doz_max', '$P28_min', '$P28LOT_min', '$P28_mindoz', '$P28Doz_min',
         '$P30', '$P30_max', '$P30LOT_max', '$P30_maxdoz', '$P30Doz_max', '$P30_min', '$P30LOT_min', '$P30_mindoz', '$P30Doz_min',
         '$P32', '$P32_max', '$P32LOT_max', '$P32_maxdoz', '$P32Doz_max', '$P32_min', '$P32LOT_min', '$P32_mindoz', '$P32Doz_min',
         '$P32W', '$P32W_max', '$P32WLOT_max', '$P32W_maxdoz', '$P32WDoz_max', '$P32W_min', '$P32WLOT_min', '$P32W_mindoz', '$P32WDoz_min',
         '$P33', '$P33_max', '$P33LOT_max', '$P33_maxdoz', '$P33Doz_max', '$P33_min', '$P33LOT_min', '$P33_mindoz', '$P33Doz_min',
         '$P35', '$P35_max', '$P35LOT_max', '$P35_maxdoz', '$P35Doz_max', '$P35_min', '$P35LOT_min', '$P35_mindoz', '$P35Doz_min',
         '$P35M', '$P35M_max', '$P35MLOT_max', '$P35M_maxdoz', '$P35MDoz_max', '$P35M_min', '$P35MLOT_min', '$P35M_mindoz', '$P35MDoz_min',
         '$P35W', '$P35W_max', '$P35WLOT_max', '$P35W_maxdoz', '$P35WDoz_max', '$P35W_min', '$P35WLOT_min', '$P35W_mindoz', '$P35WDoz_min',
         '$P38', '$P38_max', '$P38LOT_max', '$P38_maxdoz', '$P38Doz_max', '$P38_min', '$P38LOT_min', '$P38_mindoz', '$P38Doz_min',
         '$P41', '$P41_max', '$P41LOT_max', '$P41_maxdoz', '$P41Doz_max', '$P41_min', '$P41LOT_min', '$P41_mindoz', '$P41Doz_min', 
         '$P42', '$P42_max', '$P42LOT_max', '$P42_maxdoz', '$P42Doz_max', '$P42_min', '$P42LOT_min', '$P42_mindoz', '$P42Doz_min',
         '$P43', '$P43_max', '$P43LOT_max', '$P43_maxdoz', '$P43Doz_max', '$P43_min', '$P43LOT_min', '$P43_mindoz', '$P43Doz_min',
         '$P45', '$P45_max', '$P45LOT_max', '$P45_maxdoz', '$P45Doz_max', '$P45_min', '$P45LOT_min', '$P45_mindoz', '$P45Doz_min',
         '$P46', '$P46_max', '$P46LOT_max', '$P46_maxdoz', '$P46Doz_max', '$P46_min', '$P46LOT_min', '$P46_mindoz', '$P46Doz_min',
         '$P47', '$P47_max', '$P47LOT_max', '$P47_maxdoz', '$P47Doz_max', '$P47_min', '$P47LOT_min', '$P47_mindoz', '$P47Doz_min',
         '$Total', '$Total_max', '$TotalLOT_max', '$Total_maxdoz', '$TotalDoz_max', '$Total_min', '$TotalLOT_min', '$Total_mindoz', '$TotalDoz_min'     
        )
        ON DUPLICATE KEY UPDATE                                                                                                      
        Ref_Num = '$RefNum', P27 = '$P27', P27_max = '$P27_max', P27LOT_max = '$P27LOT_max', P27_maxdoz = '$P27_maxdoz', P27Doz_max = '$P27Doz_max',
        P27_min = '$P27_min', P27LOT_min = '$P27LOT_min', P27_mindoz = '$P27_mindoz', P27Doz_min = '$P27Doz_min',
        P28 = '$P28', P28_max = '$P28_max', P28LOT_max = '$P28LOT_max', P28_maxdoz = '$P28_maxdoz', P28Doz_max = '$P28Doz_max',
        P28_min = '$P28_min', P28LOT_min = '$P28LOT_min', P28_mindoz = '$P28_mindoz', P28Doz_min = '$P28Doz_min',
        P30 = '$P30', P30_max = '$P30_max', P30LOT_max = '$P30LOT_max', P30_maxdoz = '$P30_maxdoz', P30Doz_max = '$P30Doz_max',
        P30_min = '$P30_min', P30LOT_min = '$P30LOT_min', P30_mindoz = '$P30_mindoz', P30Doz_min = '$P30Doz_min',
        P32 = '$P32', P32_max = '$P32_max', P32LOT_max = '$P32LOT_max', P32_maxdoz = '$P32_maxdoz', P32Doz_max = '$P32Doz_max',
        P32_min = '$P32_min', P32LOT_min = '$P32LOT_min', P32_mindoz = '$P32_mindoz', P32Doz_min = '$P32Doz_min',
        P32W = '$P32W', P32W_max = '$P32W_max', P32WLOT_max = '$P32WLOT_max', P32W_maxdoz = '$P32W_maxdoz', P32WDoz_max = '$P32WDoz_max',
        P32W_min = '$P32W_min', P32WLOT_min = '$P32WLOT_min', P32W_mindoz = '$P32W_mindoz', P32WDoz_min = '$P32WDoz_min',
        P33 = '$P33', P33_max = '$P33_max', P33LOT_max = '$P33LOT_max', P33_maxdoz = '$P33_maxdoz', P33Doz_max = '$P33Doz_max',
        P33_min = '$P33_min', P33LOT_min = '$P33LOT_min', P33_mindoz = '$P33_mindoz', P33Doz_min = '$P33Doz_min',
        P35 = '$P35', P35_max = '$P35_max', P35LOT_max = '$P35LOT_max', P35_maxdoz = '$P35_maxdoz', P35Doz_max = '$P35Doz_max',
        P35_min = '$P35_min', P35LOT_min = '$P35LOT_min', P35_mindoz = '$P35_mindoz', P35Doz_min = '$P35Doz_min',
        P35M = '$P35M', P35M_max = '$P35M_max', P35MLOT_max = '$P35MLOT_max', P35M_maxdoz = '$P35M_maxdoz', P35MDoz_max = '$P35MDoz_max',
        P35M_min = '$P35M_min', P35MLOT_min = '$P35MLOT_min', P35M_mindoz = '$P35M_mindoz', P35MDoz_min = '$P35MDoz_min',
        P35W = '$P35W', P35W_max = '$P35W_max', P35WLOT_max = '$P35WLOT_max', P35W_maxdoz = '$P35W_maxdoz', P35WDoz_max = '$P35WDoz_max',
        P35W_min = '$P35W_min', P35WLOT_min = '$P35WLOT_min', P35W_mindoz = '$P35W_mindoz', P35WDoz_min = '$P35WDoz_min',
        P38 = '$P38', P38_max = '$P38_max', P38LOT_max = '$P38LOT_max', P38_maxdoz = '$P38_maxdoz', P38Doz_max = '$P38Doz_max',
        P38_min = '$P38_min', P38LOT_min = '$P38LOT_min', P38_mindoz = '$P38_mindoz', P38Doz_min = '$P38Doz_min',
        P41 = '$P41', P41_max = '$P41_max', P41LOT_max = '$P41LOT_max', P41_maxdoz = '$P41_maxdoz', P41Doz_max = '$P41Doz_max',
        P41_min = '$P41_min', P41LOT_min = '$P41LOT_min', P41_mindoz = '$P41_mindoz', P41Doz_min = '$P41Doz_min',
        P42 = '$P42', P42_max = '$P42_max', P42LOT_max = '$P42LOT_max', P42_maxdoz = '$P42_maxdoz', P42Doz_max = '$P42Doz_max',
        P42_min = '$P42_min', P42LOT_min = '$P42LOT_min', P42_mindoz = '$P42_mindoz', P42Doz_min = '$P42Doz_min',
        P43 = '$P43', P43_max = '$P43_max', P43LOT_max = '$P43LOT_max', P43_maxdoz = '$P43_maxdoz', P43Doz_max = '$P43Doz_max',
        P43_min = '$P43_min', P43LOT_min = '$P43LOT_min', P43_mindoz = '$P43_mindoz', P43Doz_min = '$P43Doz_min',
        P45 = '$P45', P45_max = '$P45_max', P45LOT_max = '$P45LOT_max', P45_maxdoz = '$P45_maxdoz', P45Doz_max = '$P45Doz_max',
        P45_min = '$P45_min', P45LOT_min = '$P45LOT_min', P45_mindoz = '$P45_mindoz', P45Doz_min = '$P45Doz_min',
        P46 = '$P46', P46_max = '$P46_max', P46LOT_max = '$P46LOT_max', P46_maxdoz = '$P46_maxdoz', P46Doz_max = '$P46Doz_max',
        P46_min = '$P46_min', P46LOT_min = '$P46LOT_min', P46_mindoz = '$P46_mindoz', P46Doz_min = '$P46Doz_min',
        P47 = '$P47', P47_max = '$P47_max', P47LOT_max = '$P47LOT_max', P47_maxdoz = '$P47_maxdoz', P47Doz_max = '$P47Doz_max',
        P47_min = '$P47_min', P47LOT_min = '$P47LOT_min', P47_mindoz = '$P47_mindoz', P47Doz_min = '$P47Doz_min',
        Total = '$Total', Total_max = '$Total_max', TotalLOT_max = '$TotalLOT_max', Total_maxdoz = '$Total_maxdoz', TotalDoz_max = '$TotalDoz_max',
        Total_min = '$Total_min', TotalLOT_min = '$TotalLOT_min', Total_mindoz = '$Total_mindoz', TotalDoz_min = '$TotalDoz_min'
    still it did not update but the good is it did not save again.

    Thank you

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,495
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Did it give an error?

    Echo out the query, and then copy and paste it in phpMyAdmin and see what happens

  5. #5
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No error...the output is 1.

    I tried everything but still I'm failed..I don't know what's wrong in my syntax.

    I will attach my whole code for your better understanding..

    Thank you so much...
    Attached Images Attached Images
    Attached Files Attached Files

  6. #6
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,707
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    to use INSERT ON DUPLICATE UPDATE syntax you must have a unique index indicating the columns you want to prevent duplicates in. So if you have say five specific columns that can't have duplicate values then you create your unique index on those five columns UNIQUE(col3,col6,col22,col34,col45) for example. So you could have duplicate values within each of those columns or three of five for example, but all five of those values can't be duplicates of another row with those five values already existing. At that point it would update instead of insert.

  7. #7
    SitePoint Guru
    Join Date
    Oct 2011
    Posts
    658
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a lot of columns, and I don't want to have a duplicate of those columns. I want is only one row should be save. If I edit my input data it will only update it.

    I don't know why the On duplicate Key Update did not work in my code.

    Thank you

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    I don't know why the On duplicate Key Update did not work in my code.
    neither do we, because you forgot to share with us what UNIQUE keys you have
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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