Hi,
In my MySQL DB, I have a user table with id, username, email, phone columns. Username, email and phone columns are unique, i.e. no two users can have the same username, no two users can have the same email, no two users can have the same phone.
When creating a new user with my PHP script, checking for uniqueness is easy, I simply check if any of the provided username, email or phone already exists in the table.
My issue is with updating the user info. How can I do a PHP check, to see if either the username, email or phone already exists on another user when I am updating the user info?
For example, letâs say I have two users in my table with usernames user1 and user2. I want to edit the username for user1. How can I make sure that if I enter user2 as username, my PHP script will give an alert because there is another user with that username?
MySQL has the Unique key, but I want to ensure uniqueness via my PHP script. Or, does MySQL send an error response when a duplicate value for a unique key is trying to be inserted? I checked error logs but didnât see.
What I am trying to figure out is the logic/algorithm, not the specific code.
Thanks for any ideas.