
105
DEVELOPING
COLDFUSION 9 APPLICATIONS
The CFML Programming Language
Las
t
upda
te
d 8/5/2010
<cfif StructIsEmpty(attributes.empinfo)>
<cfoutput>
Error. No employee data was passed.<br>
</cfoutput>
<cfexit method="ExitTag">
<cfelse>
<!--- Add the employee --->
<cfquery name="AddEmployee" datasource="cfdocexamples">
INSERT INTO Employees
(FirstName, LastName, Email, Phone, Department)
VALUES (
'#attributes.empinfo.firstname#' ,
'#attributes.empinfo.lastname#' ,
'#attributes.empinfo.email#' ,
'#attributes.empinfo.phone#' ,
'#attributes.empinfo.department#' )
</cfquery>
</cfif>
<cfoutput>
<hr>Employee Add Complete
</cfoutput>
Reviewing the code
The following table describes the code:
Structure functions
You can use the following functions to create and manage structures in ColdFusion applications. The table describes
the purpose of each function and provides specific, but limited, information that can assist you in determining whether
to use the function instead of other technique.
All functions except
StructDelete
throw an exception if a referenced key or structure does not exist.
For more information on these functions, see the
CFML Reference.
Code
Description
<cfif StructIsEmpty(attributes.empinfo)>
<cfoutput>
Error. No employee data was passed.<br>
</cfoutput>
<cfexit method="ExitTag">
If the custom tag was called without an
empinfo
attribute,
displays an error message and exit the tag.
<cfelse>
<!--- Add the employee --->
<cfquery name="AddEmployee" datasource="cfdocexamples">
INSERT INTO Employees
(FirstName, LastName, Email, Phone, Department)
VALUES (
'#attributes.empinfo.firstname#' ,
'#attributes.empinfo.lastname#' ,
'#attributes.empinfo.email#' ,
'#attributes.empinfo.phone#' ,
'#attributes.empinfo.department#' )
</cfquery>
</cfif>
Add the employee data passed in the empinfo structure to the
Employees table of the cfdocexamples database.
Use direct references to the structure entries, not StructFind
functions.
If the database does not support automatic generation of the
Emp_ID key, add an Emp_ID entry to the form and add it to the
query.
<cfoutput>
<hr>Employee Add Complete
</cfoutput>
Display a completion message. This code does not have to be
inside the
cfelse
block because the cfexit tag prevents it from
being run if the empinfo structure is empty.