Since I have been out of CF dev for several years, I thought I would work on
some simple stuff. Looking at this code below, can this be improved?
I am using CF 10 with MySQL backend. I did not use stored procs because I have
having issues with making them on MySQL since I am new to the db, so I know
that is one improvement that I could make.
Thanks,
Bruce
Code snippet below:
<!--- Insert users information into the database --->
<cfquery datasource="#request.datasource#">
INSERT INTO themovement.users
(firstname, lastname, email, zipcode, groupemail, orgid)
VALUES
(<cfqueryparam value="#form.firstname#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#form.lastname#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#form.email#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#form.zipcode#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#form.friendemail#" cfsqltype="cf_sql_varchar">,
<cfqueryparam value="#form.selectOrg#" cfsqltype="cf_sql_integer">)
</cfquery>
<!--- Select the org ID and DL count from the database using the form variable
for a match --->
<cfquery datasource="#request.datasource#" name="qgetOrgID">
SELECT orgid, dlcount
FROM themovement.dlcount
WHERE orgid = <cfqueryparam value="#form.selectOrg#"
cfsqltype="cf_sql_integer">
</cfquery>
<!--- If there is already an org ID in the database, then update the dlcount by
one --->
<cfif qgetorgID.recordcount GT 0>
<cfquery datasource="#request.datasource#">
UPDATE themovement.dlcount
set dlcount = <cfqueryparam value="#qgetOrgID.dlcount#"
cfsqltype="cf_sql_integer"> + 1
Where orgid = <cfqueryparam value="#form.selectORg#"
cfsqltype="cf_sql_integer">
</cfquery>
<!--- Otherwise we can assume that the org ID is not in the database and add it
here, and set the DL count to 1 --->
<cfelse>
<cfquery datasource="#request.datasource#">
INSERT INTO themovement.dlcount
(orgid, dlcount)
VALUES
(<cfqueryparam value="#form.selectOrg#" cfsqltype="cf_sql_integer">,
<cfqueryparam value="1" cfsqltype="cf_sql_integer">)
</cfquery>
</cfif>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive:
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:353322
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm