Solved

cfquery within a cfscript

Posted on 2008-10-24
6
178 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
Comment Utility
why do you want use <cfscript> It will perfectly fit in withing coldfusion code
0
 
LVL 1

Author Comment

by:mopar003
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 9

Accepted Solution

by:
Andrew Maurer earned 500 total points
Comment Utility



<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
Comment Utility
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
Comment Utility
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Suggested Solutions

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

18 Experts available now in Live!

Get 1:1 Help Now