Solved

cfquery within a cfscript

Posted on 2008-10-24
6
179 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
Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Script 12 134
Application launch issue with Apache Tomcat 5 21
How to find Tomcat initial memory and Max memory through command line windows 12 145
PHP in Apache server 20 88
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…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

910 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now