Solved

cfquery within a cfscript

Posted on 2008-10-24
6
181 Views
Last Modified: 2013-12-24
Is there any way to perform the below function?  I know this particular way does not work, but is there a way to mimic what this would do?
<cfscript>
    /*validate form data*/
    if(form.ProjectName EQ "") { err1 = "class=err"; }
    if(form.FirstName EQ "") { err2 = "class=err"; }
    if(form.LastName EQ "") { err3 = "class=err"; }
    if(form.Department EQ "") { err4 = "class=err"; }
    if(form.Email EQ "") { err5 = "class=err"; }
    if(err1&err2&err3&err4&err5 NEQ "") {
	WriteOutput("Error occurred. Please check the highlighted fields.");
    } else {
  
    <cfquery name="insertDesign" datasource="shssrDesignRequest">
    INSERT INTO DesignRequest 
    (ProjectName, ProjectDescription, RequesterName) 
    VALUES	('#form.ProjectName#', '#form.ProjectDescription#', '#form.ad_fname# #form.ad_lname#')
    </cfquery>
	
    }
</cfscript>

Open in new window

0
Comment
Question by:mopar003
  • 3
  • 2
6 Comments
 
LVL 19

Expert Comment

by:erikTsomik
ID: 22798894
why do you want use <cfscript> It will perfectly fit in withing coldfusion code
0
 
LVL 1

Author Comment

by:mopar003
ID: 22799798
I would prefer to use the cfscript for long bulk scripting.  The code above is a snippet of the actual in use code.  I am unsure of a query item being run in the script tag however.  The code included should give someone an idea of what I am looking to do.
0
 
LVL 9

Expert Comment

by:Andrew Maurer
ID: 22800941
I agree with you mopar.. cfscript is much more readable...

k.. so funny thing is, I just found this out today... but if you want to use tags that aren't available in cfscript, you have to create a function.. so here is your code... standby..
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 9

Accepted Solution

by:
Andrew Maurer earned 500 total points
ID: 22800964


<cffunction name="runquery" access="private" returntype="void">
	<cfargument name="ProjectName" default="0">
	<cfargument name="ProjectDescription" default="0">
	<cfargument name="ad_fname" default="0">
	<cfargument name="ad_lname" default="0">
 
 	<cfif arguments.ProjectName NEQ 0
    	AND arguments.ProjectDescription NEQ 0
    	AND arguments.ad_fname NEQ 0
    	AND arguments.ad_lname NEQ 0 >
        <cfquery name="insertDesign" datasource="shssrDesignRequest">
            INSERT INTO DesignRequest 
            (ProjectName, ProjectDescription, RequesterName) 
            VALUES      (	
                            '#arguments.ProjectName#',
                            '#arguments.ProjectDescription#',
                            '#arguments.ad_fname# #arguments.ad_lname#'
                         )
        </cfquery>
    </cfif>
 
	<cfreturn />
</cffunction>
 
 
<cfscript>
    /*validate form data*/
    if(form.ProjectName EQ "") { err1 = "class=err"; }
    if(form.FirstName EQ "") { err2 = "class=err"; }
    if(form.LastName EQ "") { err3 = "class=err"; }
    if(form.Department EQ "") { err4 = "class=err"; }
    if(form.Email EQ "") { err5 = "class=err"; }
    if(err1&err2&err3&err4&err5 NEQ "") {
        WriteOutput("Error occurred. Please check the highlighted fields.");
    } else {
  
   		runquery(
        		form.ProjectName,
                form.ProjectDescription,
                form.ad_fname,
                form.ad_lname
        		);
        
    }
</cfscript>

Open in new window

0
 
LVL 1

Author Closing Comment

by:mopar003
ID: 31509755
Good solution to the problem.  A lot of workaround, unfortunately, but useful none the less.  Thanks you for your help.
0
 
LVL 9

Expert Comment

by:Andrew Maurer
ID: 22801284
True... extra work... but hey... now that function is reusable if you stick it in a cfc AND its out of the way... not muckn' up your pretty code ;)

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question