Is it possible to check which fields were changed?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newbie93
    New Member
    • May 2012
    • 8

    Is it possible to check which fields were changed?

    Hello everyone,
    I am wondering if it is possible to check *which* rows were updated when a user edits a field.
    This is my problem: I have a list of users and it is important that no usernames are repeated. I have already created a function that checks if the username already exists in the database when a user is intially added. However, I am not sure how I can check if, once the username field is *updated*, if the newly updated field already exists.
    Obviously, the same function cannot be used when the user is edited because even when the username fieldname is *not* updated, the result will always be "yes, it already exists".
    Hopefully you guys can help me brainstorm a solution, I am stuck at the moment.
    Thank you :-)
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    the most simple solution is to give the database field a UNIQUE KEY constraint. any attempts to create or modify a value to an already existing value will fail.

    Comment

    • newbie93
      New Member
      • May 2012
      • 8

      #3
      Hi, thanks for the suggestion. I ended up simply checking if 1 already exists (as opposed to if 0 exist, as the function for adding a user did)

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        but that leaves you with the problem that should that check be skipped (for whatever reason) you can end up with duplicate names. UNIQUE KEY doesn’t allow duplicate names on DB level.

        Comment

        • newbie93
          New Member
          • May 2012
          • 8

          #5
          hmm, yes, you are right. I will take your suggestion. Thank you

          Comment

          Working...