Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

cfquery within a cfscript

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
mopar003
Asked:
mopar003
  • 3
  • 2
1 Solution
 
erikTsomikSystem Architect, CF programmer Commented:
why do you want use <cfscript> It will perfectly fit in withing coldfusion code
0
 
mopar003Author Commented:
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
 
Andrew MaurerCommented:
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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Andrew MaurerCommented:


<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
 
mopar003Author Commented:
Good solution to the problem.  A lot of workaround, unfortunately, but useful none the less.  Thanks you for your help.
0
 
Andrew MaurerCommented:
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now