Answered
CFC question
The register cfc should check that the username in the form
doesn`t already exist and if it doesn`t then insert the user into
the db. The result will be returned to the index.cfm page where the
users is either sent to another page or sees a message syaing that
the users already exists. I have had a good crack at it but it
doesn`t seem to be doing anything. Thanks for any advice
register.cfc
<cfcomponent>
<cffunction access="public" name="adduser" output="0">
<!--- add new user function --->
<!--- username and password required --->
<cfargument name="cfcUsername" type="string" required="1" />
<cfargument name="cfcPassword" type="string" required="1" />
<cfset variables.verificationKey = CreateUUID()>
<!--- query the SecurityDB for the passed username --->
<cfquery name="checkusername" datasource="SecurityDB" username="root" password="riveravon">
SELECT username
FROM Security
WHERE username = '#arguments.cfcUsername#'
</cfquery>
<!--- if the username already exists then return that result--->
<cfif checkusername.recordCount>
<cfreturn checkusername.recordCount />
<cfelse>
<!--- the username doesn`t exist so enter user´s details and return that --->
<cfquery name="newUser" datasource="SecurityDB" username="root" password="riveravon">
INSERT INTO security (username, password, activationcode)
VALUES ('#form.username#', '#form.password#', '#variables.verificationKey#')
</cfquery>
<cfreturn checkusername.recordCount />
</cfif>
</cffunction>
</cfcomponent>
index.cfm
<cfif structKeyExists(form,"adduser")>
<!--- The user pressed the register insert button --->
<cfinvoke
component="register"
method="adduser"
returnVariable="adduser"
cfcUsername="#form.username#">
<cfset adduser="#adduser#">
</cfif>
<form name="adduser" method="post" action="index.cfm">
<DIV align=center>Username:<INPUT id=username name=username>
<br>
Password:
<INPUT id=password name=password>
</DIV>
<input tabindex="3" type="image" name="adduser" src="images/register.gif" height=43 width=164 border="0"></A></DIV>
</form>
<cfif isDefined("variables.adduser")>
<cfif variables.adduser NEQ 0>
<b>This Username already exists! Please enter another</b>
<cfelse>
<cflocation url="activation.cfm" addtoken="No">
</cfif>
</cfif>
register.cfc
<cfcomponent>
<cffunction access="public" name="adduser" output="0">
<!--- add new user function --->
<!--- username and password required --->
<cfargument name="cfcUsername" type="string" required="1" />
<cfargument name="cfcPassword" type="string" required="1" />
<cfset variables.verificationKey = CreateUUID()>
<!--- query the SecurityDB for the passed username --->
<cfquery name="checkusername" datasource="SecurityDB" username="root" password="riveravon">
SELECT username
FROM Security
WHERE username = '#arguments.cfcUsername#'
</cfquery>
<!--- if the username already exists then return that result--->
<cfif checkusername.recordCount>
<cfreturn checkusername.recordCount />
<cfelse>
<!--- the username doesn`t exist so enter user´s details and return that --->
<cfquery name="newUser" datasource="SecurityDB" username="root" password="riveravon">
INSERT INTO security (username, password, activationcode)
VALUES ('#form.username#', '#form.password#', '#variables.verificationKey#')
</cfquery>
<cfreturn checkusername.recordCount />
</cfif>
</cffunction>
</cfcomponent>
index.cfm
<cfif structKeyExists(form,"adduser")>
<!--- The user pressed the register insert button --->
<cfinvoke
component="register"
method="adduser"
returnVariable="adduser"
cfcUsername="#form.username#">
<cfset adduser="#adduser#">
</cfif>
<form name="adduser" method="post" action="index.cfm">
<DIV align=center>Username:<INPUT id=username name=username>
<br>
Password:
<INPUT id=password name=password>
</DIV>
<input tabindex="3" type="image" name="adduser" src="images/register.gif" height=43 width=164 border="0"></A></DIV>
</form>
<cfif isDefined("variables.adduser")>
<cfif variables.adduser NEQ 0>
<b>This Username already exists! Please enter another</b>
<cfelse>
<cflocation url="activation.cfm" addtoken="No">
</cfif>
</cfif>