I need to create a file to use as a template in coldfusion, so I need to insert cold fusion code to a sql database table using cold fusion or create a file with cffile? Every thing I try to use,it doesn't work because I think it is reading the variables any way to do this?

I tried this

<cfsavecontent variable="HTMLCODE">
<cfquery name="get_member" datasource="#application.dsn#">	SELECT * FROM member where userid <> '102'</cfquery><cfmail to="#get_member.Email#" from="#get_member.Email#" subject="Example email" server="#application.mailserver#"><cfmailpart type="html"><cfoutput>#DateDiff("d", Now(), CreateDate(2012,8,1))# Days to Go.</cfoutput><br /><br /><img src="http://image/61.jpg">   </cfmailpart></cfmail>
</cfsavecontent>

<cffile action = "write" 
   file = "c:\temp\202.cfm" 
   output = "#HTMNCODE#">

and I tried this

<cfquery name="Update_Goal" datasource="#application.dsn#">
					INSERT INTO goals
					(UserID,
					 Task,
					 operation,
					 Url,
					 StartDate,
                     StartTime,
                     EndDate,
                     EndTime,
					 Interval,
					 ResolveURL,
					 Publish,
					 goalfile,
					 goalpath,
					 RequestTimeOut,
					 goal1,
					 email1,
					 email2,
					 email3,
					 email4,
					 email5)
					VALUES
					('<cfif IsDefined("session.userID")>#session.userid#</cfif>',
					 '<cfif IsDefined("form.task")>#form.task#</cfif>',
					 '<cfif IsDefined("form.operation")>#form.operation#</cfif>',
					 '<cfif IsDefined("form.url")>#form.url#</cfif>',
					 '<cfif IsDefined("form.StartDate")>#form.StartDate#</cfif>',
					 '<cfif IsDefined("form.StartTime")>#form.StartTime#</cfif>',
					 '<cfif IsDefined("form.EndDate")>#form.EndDate#</cfif>',
					 '<cfif IsDefined("form.EndTime")>#form.EndTime#</cfif>',
					 '<cfif IsDefined("form.interval")>#form.interval#</cfif>',
					 '<cfif IsDefined("form.resolveurl")>#form.ResolveURL#</cfif>',
					 '<cfif IsDefined("form.publish")>#form.Publish#</cfif>',
                     '<cfquery name="get_member" datasource="#application.dsn#">	SELECT * FROM member where userid <> '102'</cfquery><cfmail to="#get_member.Email#" from="#get_member.Email#" subject="Example email" server="#application.mailserver#"><cfmailpart type="html"><cfoutput>#DateDiff("d", Now(), CreateDate(2012,8,1))# Days to Go.</cfoutput><br /><br /><img src="http://image/61.jpg">   </cfmailpart></cfmail>',
                     '<cfif IsDefined("form.goalpath")>#form.goalpath#</cfif>',
                     '<cfif IsDefined("form.RequestTimeOut")>#form.RequestTimeOut#</cfif>',
                     '#htmlcode#',
                     '<cfif IsDefined("form.email1")>#form.email1#</cfif>',
                     '<cfif IsDefined("form.email2")>#form.email2#</cfif>',
                     '<cfif IsDefined("form.email3")>#form.email3#</cfif>',
                     '<cfif IsDefined("form.email4")>#form.email4#</cfif>',
                     '<cfif IsDefined("form.email5")>#form.email5#</cfif>')
					</cfquery>

I actually figured it out I stored my cold fusion code in a table in the database then when I run my code it pulls the cf code as a variable then updates another table

Easiest way to do this would be to replace the < > with HTML entities before they go in the <cfsavecontent>. Then reverse the process before using it in your outputted template.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.