|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here! |
|
#1
|
||||
|
||||
|
Im creating an application that requires a person to login with a username and password before they use it. They get to choose their own username by a form that CFINPUTs it in the database. I need a code that will not allow usernames to be repeated. In other words that no 2 people have the same username.
thanks |
|
#2
|
|||
|
|||
|
When the user submits the form, just query the database and make sure the same user name isn't already in the table. If it isn't, proceed. If it is, redisplay the form with an error message.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
Keep this in mind
Depending on what database platform you're using, data in the db may be case sensitive. Keep this in mind when working with usernames. You may want to store them in the database either as upper or lower case strings.
e.g. <cfquery datasource="#datasource#"> INSERT INTO users (username) VALUES ('#LCase(form.username)#') </cfquery> then when you query the data from the database, you can reference like the following <cfquery name="qryUsers" datasource="#datasource#"> SELECT username FROM users WHERE username = '#LCase(form.username)#' </cfquery> This will help ensure you don't get usernames mixed up. Also, you may also want to place a UNIQUE contraint on the username field to give that piece of mind that duplicates will never be inserted. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Dont repeat username |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|