Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cfif not uotputting 'else' part of clause

Status
Not open for further replies.

cynaptic

Programmer
Joined
Sep 13, 2001
Messages
54
Location
GB
am trying to set up a login page. the actual guts of the login works fine except for the fact that if the recordcount is '0' the <cfelse> part of the cfif clause does not appear in the resultant page. am foxed totally.


<cfoutput query=&quot;login&quot;>

<cfif login.recordcount gt 0>

<cfset logged = &quot;true&quot;>

<a href=&quot;access.cfm&quot; target=&quot;_parent&quot;>go on in #UserName#</a>

<cfelse>

bad luck - <a href=&quot;login.cfm&quot; target=&quot;_self&quot;>try again</a>

</cfif>


</cfoutput>
 
Try switching the order of the cfoutput and the first cfif:

<cfoutput query=&quot;login&quot;>

<cfif login.recordcount gt 0>

...


changes to :

<cfif #login.recordcount# gt 0>

<cfoutput query=&quot;login&quot;>

etc., etc.,
</cfoutput>

<cfelse>

<cflocation URL=&quot;login.cfm&quot;>

</cfif> John Hoarty
jhoarty@quickestore.com
 
John

you are a life saver, i was about to throw myself and the computer out of the window. if works a treat - but could you explain why please, what is the logic behind the cure? I am a bit crap at CF and would like to get better:)

Alex
 
Sure, if &quot;RecordCount&quot; is zero, then there is no output for the query &quot;login&quot;! To illustrate the point, you could have also used the following code, which is exactly the same as your original post, except the ' query=&quot;login&quot; ' part was removed from the cfoutput tag. This would probabl have been the better response to your question:

<cfoutput>

<cfif login.recordcount gt 0>

<cfset logged = &quot;true&quot;>

<a href=&quot;access.cfm&quot; target=&quot;_parent&quot;>go on in #UserName#</a>

<cfelse>

bad luck - <a href=&quot;login.cfm&quot; target=&quot;_self&quot;>try again</a>

</cfif>


</cfoutput> John Hoarty
jhoarty@quickestore.com
 
Thanks John. Much appreciated.

Alex
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top