Solved

cfquery within a cfscript

Posted on 2008-10-24
6
182 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

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 176
Use System DSN 6 89
AWS Advice on using WHM/cPanel 1 80
Moving web servers into a DMZ? 3 67
This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 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