How to stop adding/updating duplicate username and email?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mangal
    New Member
    • Dec 2006
    • 9

    How to stop adding/updating duplicate username and email?

    Hello,

    I am creating a web application in which registrations are open as usual. My doubt is, if some one try to create an account by an email-id like 'foo@gmail.com' , at same time other user also try to create account by same emailid 'foo@gmail.com' , what will happen in this case? I have added a validation to check the duplicate email-id in the database before insert and update in my script but i am thinking if both request submitted on same time then what will happen? will PostgreSQL add both records into the table? Please suggest me how to handle such situations?

    I heard that such type of problem can be prevent by row locking. Could you please help me to sort out it?

    Mangal Kumar
  • rski
    Recognized Expert Contributor
    • Dec 2006
    • 700

    #2
    Create a unique index or primary key on the email-id field and you will not have to check for duplicates, database will do it such validation for you. After inserting a row you can catch an exception and show user a message that such email already exists.

    Comment

    • mangal
      New Member
      • Dec 2006
      • 9

      #3
      Thank you

      I will try it.

      Comment

      • Leanne84
        New Member
        • Aug 2012
        • 1

        #4
        rski, thanks a lot for your answer! i find it also pretty useful! Very good!


        _______________ __
        <link removed by moderator>
        Last edited by Rabbit; Aug 22 '12, 04:00 PM. Reason: Your link has been removed per the forum policy.

        Comment

        Working...