| | |
autocreate username
Please support our ColdFusion advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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':
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.
If you a user table and the last userID is 20, this will result in a username of 'mkwe21'.
I hope this helps.
ColdFusion Syntax (Toggle Plain Text)
<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)
<cfquery datasource="whatever your datasource is" name="qryGetMaxUserID"> DECLARE @userID varchar(10); SELECT @userID = CAST((SELECT MAX(userID) + 1 AS newUserID FROM users) AS varchar(10)); INSERT users ( username ) VALUES ( '#username#' + @userID ) </cfquery>
If you a user table and the last userID is 20, this will result in a username of 'mkwe21'.
I hope this helps.
![]() |
Other Threads in the ColdFusion Forum
- Previous Thread: Coldfusion and Cookies
- Next Thread: Checkboxes checked
| Thread Tools | Search this Thread |





