Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

cfquery within a cfscript

Posted on 2008-10-24
6
Medium Priority
?
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 
LVL 9

Accepted Solution

by:
Andrew Maurer earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
What You Need to Know when Searching for a Webhost Provider
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

704 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