To begin with Among the finest to express gratitude! I really like this website and that i love how useful everybody is here now! I truly thank you for help! :)

Okay, so to my problem. I've got a registration.php page I made and I have to see if a username has already been during my database to ensure that I will not have 2 people with similar title...

This is how I'm placing the consumer info in to the database (username, password, date of registration, etc.):

mysql_query("INSERT INTO UserDb (ID, TimeStamp, UserName, Password) VALUES ('$ipaddress', NOW(), '$user_username', '$user_password')");

How do i make sure that database "UserDb" underneath the "UserName" area to make certain anyone's variable "$user_username" does not already exist?

Hope which makes sense... Thanks for all your help!

You may make the UserName a distinctive area. MySQL will won't place a brand new record when the username already is available.

Alternatively you are able to operate a query trying to find the username. Whether it does not is available, place it. Wrap this right into a transaction so you can be certain that whenever you've looked for any user, one more brand new one with similar title was added before you decide to add the brand new one.

produce a unique key on UserName and when the Place errors out, look into the error number.

You may make the username area within the database a principal key or unique, which guarantees the username originality within the database.

Then, by trying to place a previously existing username the mysql_query() function will fail, returning FALSE.

On top of that, it is best to query the database for the presence of the username, utilizing a simple choose statement:

SELECT username FROM table WHERE username='$php_username_var';

It is best to look for the username first, instead of with respect to the database to inform you via error - always easier to be explicit instead of have functionality implied.

Also, you may want to think about the situation where you will find a number of existing records with similar username.

For instance, if your user subscribes for any subscription, cancels following a couple of several weeks, after which subscribes again later.

Sometimes it is best to re-open the account, and in other cases just to produce a brand new one...For the reason that situation it may be ok to possess duplicate rows with similar username, as long as just the current the first is active, and also the relaxation are for historic confirming reasons.

Actually, you will need the duplicate rows when the old user instances are recommended inside your billing tables, notes, etc. Should you erased the consumer, it might cause difficulties with your confirming.

A suggestion too - think about using anyone's current email address his or her username - you realize it is a string that's unique for them, provides you with a default method to contact them, and may be validated at register.