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.
Posts: n/a