SitePoint Sponsor

User Tag List

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

    Problem in mysql_query Insert with On Duplicate key

    Hi...

    Before I have no problem in using On Duplicate Key, but now i have because of using time function.

    Before I only have insert query:

    Code:
    $result = mysql_query("INSERT INTO regular_sum_hours(EMP_NO, Hours) SELECT EMP_NO, sec_to_time(SUM(time_to_sec(Rendered))) FROM regular_dtr_total GROUP BY EMP_NO") or die(mysql_error());
    And now I think that I need to add a syntax for Update, so i revise my code:
    Code:
    $result = mysql_query("INSERT INTO regular_sum_hours(EMP_NO, Hours) SELECT EMP_NO, sec_to_time(SUM(time_to_sec(Rendered))) FROM regular_dtr_total GROUP BY EMP_NO ON DUPLICATE KEY EMP_NO = EMP_NO, Hours = sec_to_time(SUM(time_to_sec(Rendered)))") or die(mysql_error());
    and I got a problem in this part:

    Hours = sec_to_time(SUM(time_to_sec(Rendered)))")


    Thank you

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,017
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by newphpcoder View Post
    and I got a problem in this part:
    no, you don't

    you got a problem in this part here --
    Code:
    ON DUPLICATE KEY EMP_NO = EMP_NO,
    did you test this query outside of php before trying to incorporate it into your php code?

    if you had done so, i'm betting you would have got a more informative error message
    r937.com | rudy.ca | 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
  •