Using cfoutput within a cfif statement

Posted: 02-24-2005, 07:00 PM
I am trying to setup a form validation, what i need to do is look at the
Specimen Number entered and compare it against the database to see if it
already exists. What i am trying now is to place a query and a cfif statement
just before the insert query runs, and using the <cfabort> to stop it if a
match is found.

Here is what i have so far.

<cfquery name="rsSpecNoVerify" datasource="TNMP_DB_be_TRACS">
SELECT SPEC_NO FROM URINE WHERE SPEC_NO = <CFQUERYPARAM
CFSQLTYPE="CF_SQL_VARCHAR" VALUE="#FORM.SpecimenNum#">
</cfquery>
<cfif "<cfoutput>#rsSpecNoVerify.SPEC_NO#</cfoutput>" EQ #FORM.SpecimenNum#>
<h1>ERROR! Duplicate Specimen Number</h1>
<cfabort>
</cfif>

I don't get any errors but it continues to insert the record even though i am
entering a specimen number that i know already exists. I am using the
cfqueryparam statement because while the field is numeric 90% of the time there
are some tests that have a number that starts with "hh" so the field type is
set to string, and without the cfqueryparam i get a data type mismatch.

Should i be going about this a different way ? I believe the problem is with
the cfoutput being inside the cfif statement, but i can't seem to find a way to
fix it, i tried it without the " but i get a syntax error when i do.

I am still new to CF and web development, so i am still working on the Syntax.

Thanks for any help.

Reply With Quote

Responses to "Using cfoutput within a cfif statement"

Paul Whitham TMM
Guest
Posts: n/a
 
Re: Using cfoutput within a cfif statement
Posted: 02-24-2005, 08:32 PM
I wouldn't bother with a test like you are doing because essentially with
your Query you are are only interested if the recordset contains aby values,
so you could achieve it with the following simplier test

<cfif rsSpecNoVerify.Recordcount GT 0>
<h1>ERROR! Duplicate Specimen Number</h1>
<cfabort>
</cfif>


--
Regards

Paul Whitham
Macromedia Certified Professional for Dreamweaver MX2004
Valleybiz Internet Design
www.valleybiz.net

Team Macromedia Volunteer for Ultradev/Dreamweaver MX
http://www.macromedia.com/support/fo...eam_macromedia

"USPO" <webforumsuser@macromedia.com> wrote in message
news:cvlbo4$j1f$1@forums.macromedia.com...
> I am trying to setup a form validation, what i need to do is look at the
> Specimen Number entered and compare it against the database to see if it
> already exists. What i am trying now is to place a query and a cfif
statement
> just before the insert query runs, and using the <cfabort> to stop it if a
> match is found.
>
> Here is what i have so far.
>
> <cfquery name="rsSpecNoVerify" datasource="TNMP_DB_be_TRACS">
> SELECT SPEC_NO FROM URINE WHERE SPEC_NO = <CFQUERYPARAM
> CFSQLTYPE="CF_SQL_VARCHAR" VALUE="#FORM.SpecimenNum#">
> </cfquery>
> <cfif "<cfoutput>#rsSpecNoVerify.SPEC_NO#</cfoutput>" EQ
#FORM.SpecimenNum#>
> <h1>ERROR! Duplicate Specimen Number</h1>
> <cfabort>
> </cfif>
>
> I don't get any errors but it continues to insert the record even though
i am
> entering a specimen number that i know already exists. I am using the
> cfqueryparam statement because while the field is numeric 90% of the time
there
> are some tests that have a number that starts with "hh" so the field type
is
> set to string, and without the cfqueryparam i get a data type mismatch.
>
> Should i be going about this a different way ? I believe the problem is
with
> the cfoutput being inside the cfif statement, but i can't seem to find a
way to
> fix it, i tried it without the " but i get a syntax error when i do.
>
> I am still new to CF and web development, so i am still working on the
Syntax.
>
> Thanks for any help.
>

Reply With Quote
USPO
Guest
Posts: n/a
 
Re: Using cfoutput within a cfif statement
Posted: 02-24-2005, 08:46 PM
Paul,
Thanks, i didn't even think about that, makes perfect sense though, i only
care if the query returns any values at all. How does Homer say it "Doh".

Again, thanks much, it worked like a champ.
P.S. Pass along my thanks to the Dev team that created Dreamweaver, i truly
love working with it & the more i learn the more i like it.

Reply With Quote
 
LinkBack Thread Tools Search this Thread Display Modes
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
my own database / CFOUTPUT works... now to add data viaCFML! jsabarese Coldfusion - Getting Started 8 05-31-2005 02:11 AM
Getting CFOUTPUT to Repeat otowny407 Coldfusion Database Access 1 03-04-2005 01:52 AM
cfoutput - show hyperlink for visitor jsabarese Dreamweaver AppDev 1 02-20-2005 04:11 PM
<cfoutput query> and TABLE formatting flashrx Coldfusion - Getting Started 1 02-18-2005 04:24 PM
Expected end of statement onyx23 Dreamweaver AppDev 0 02-16-2005 03:06 PM