Secure parsing of data in MySQL query?
I am quite new to CF, but want to make sure the variables that get put in a query are secure and dont leave me open to hacks. I made a simple guestbook since I'm learning.
Here is my CFC
<cfcomponent>
<!--- GET COMMENTS --->
<cffunction name="get_comments" access="public" returntype="query">
<cfquery name="q_comments" datasource="guestbook">
SELECT name, location, comment, timestamp
FROM comments
ORDER BY timestamp DESC
</cfquery>
<cfreturn q_comments>
</cffunction>
<!--- INSERT COMMENT --->
<cffunction name="insert_comment" access="public" returntype="void">
<cfargument name="form_data" type="struct" required="yes">
<cfquery datasource="guestbook">
INSERT INTO comments
(name, location, comment)
VALUES
('#form_data.name#', '#form_data.location#', '#form_data.comment#')
</cfquery>
</cffunction>
</cfcomponent>
Here is index.cfm
<cfif IsDefined("form.submit")><!--- one field is sufficient --->
<!--- define the struct to be passed to the function --->
<cfset data.comment = trim(form.comment)>
<cfset data.name = trim(form.name)>
<cfset data.location = trim(form.location)>
<cfif comment NEQ "">
<cfif name EQ "">
<cfset name = "Anonymous">
</cfif>
<cfinvoke
component="guestbook.cfc.db"
method="insert_comment">
<cfinvokeargument name="form_data" value="#data#"/>
</cfinvoke>
<cfelse>
<cfset message="Comment is required!">
</cfif>
</cfif>
<cfform method="post" name="guestbook">
<label>Name </label><cfinput type="text" name="name" size="50" maxlength="50">
<label>Location </label><cfinput type="text" name="location" size="50" maxlength="50">
<label>Comment </label><textarea name="comment" cols="65" rows="10" wrap="virtual"></textarea>
<cfinput type="submit" name="submit" value="Submit">
</cfform>
