Solved

cfquery within a cfscript

Posted on 2008-10-24
6
185 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
Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

628 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