Using cfoutput within a cfif statement

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default Using cfoutput within a cfif statement

    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.

    USPO Guest

  2. Similar Questions and Discussions

    1. Repeating output with cfif statement
      I have a problem when multiple checkboxes are "turned on' when multiple values exist for a field in a database. For example: The following code...
    2. Help with cfif statement
      Can anyone help me find the correct way to write the following statement? <cfif form.user2 NEQ 15 or 50 or 51 or 52 or 53 or 55 or 200 or 223 or...
    3. Cannot put <cfoutput> around a <select> statement usinga query.
      <select name="t#this_tourn#_course_id"> <cfoutput query="get_courses"> <option value="#course_id#"> #course_name# - Par #par#</option> </select>...
    4. CFIF Statement problems
      I am trying to write a cfif statement, which shows a form only if the statemnt acts true. It is a 3 part statement, the first two parts appear to...
    5. Login error with CFIF statement
      Hi all: I'm having trouble with a login CFIF routine. The following code works fine when the login is TRUE, but when I try to login with invalid...
  3. #2

    Default Re: Using cfoutput within a cfif statement

    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
    [url]www.valleybiz.net[/url]

    Team Macromedia Volunteer for Ultradev/Dreamweaver MX
    [url]www.macromedia.com/support/forums/team_macromedia[/url]

    "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.
    >

    Paul Whitham TMM Guest

  4. #3

    Default Re: Using cfoutput within a cfif statement

    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.

    USPO Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139