943,759 Members | Top Members by Rank

Ad:
  • ColdFusion Discussion Thread
  • Unsolved
  • Views: 1500
  • ColdFusion RSS
Aug 11th, 2008
0

autocreate username

Expand Post »
can anyone help me with code to auto carete a username.
this should tahe the 4 letters of the user's name and assign a number from a sequence in a database.
basically the username should be like "comp001" but it should verify if it exists in the database. please help. im new to coldfusion
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mkwebnovice is offline Offline
1 posts
since Aug 2008
Aug 20th, 2008
0

Re: autocreate username

Here's something to start with. To get the first four characters of the user's name, use the LEFT function. Assuming you have a text box on the form called 'txtName':

ColdFusion Syntax (Toggle Plain Text)
  1. <cfset username = LEFT(form.txtName, 4) />

If the name entered in that field was 'mkwebnovice', this would give you 'mkwe'. Next, you can use the MAX function in SQL (provided you are using SQL) to get the highest ID record in your user's table. I am of course assuming that you have a users table with an auto incrementing id field. When you do your insert statement, use this function and combine it with the result of the LEFT function above.

ColdFusion Syntax (Toggle Plain Text)
  1. <cfquery datasource="whatever your datasource is" name="qryGetMaxUserID">
  2. DECLARE @userID varchar(10);
  3. SELECT @userID = CAST((SELECT MAX(userID) + 1 AS newUserID FROM users) AS varchar(10));
  4.  
  5. INSERT
  6. users
  7. (
  8. username
  9. )
  10. VALUES
  11. (
  12. '#username#' + @userID
  13. )
  14. </cfquery>

If you a user table and the last userID is 20, this will result in a username of 'mkwe21'.

I hope this helps.
Reputation Points: 23
Solved Threads: 10
Junior Poster in Training
cmhampton is offline Offline
79 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ColdFusion Forum Timeline: Coldfusion and Cookies
Next Thread in ColdFusion Forum Timeline: Checkboxes checked





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC