• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

Why does CFIF test give opposite results?

Contributor ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

I ran into an issue where a condition (CFIF) that should be true is returning false. I'm hoping someone has a nifty answer to this.

 

Here's some code I created to demonstrate the test:

<cfif url.userid is "session.userid"> <!--- Condition True --->
    My test is &lt;cfif url.userid is "session.userid"&gt;<br><br> 
    url.userid IS equal to session.userid<br><br>  
    The values are:<br>
    url.userid = <cfoutput>#url.userid#</cfoutput><br>
    session.userid = <cfoutput>#session.userid#</cfoutput><br><br>
<cfelse> <!--- Condition False --->
    My test is &lt;cfif url.userid is "session.userid"&gt;<br><br> 
    url.userid is NOT equal to session.userid<br><br>
    The values are:<br>
    url.userid = <cfoutput>#url.userid#</cfoutput><br>
    session.userid = <cfoutput>#session.userid#</cfoutput><br><br>
</cfif>

And here's how my "Condition False" code displays:

John_Allred_0-1628267562010.png

I'm stumped.

 

Thanks!
John Allred

Views

209

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Contributor , Aug 06, 2021 Aug 06, 2021

This is where you see my sheepish expression as I solve my own problem. For what it's worth, I'd love one of the gurus to explain "WHY", but here's the solution:

 

I was using "IS" between the two variables. When I changed IS to EQ and removed the quotes, all is well. 

 

So, this works as expected. With the variables holding the same value:

 

 

<cfif url.userid eq session.userid>

 

Could it be that I was comparing a numeric value with a text value?

 

Votes

Translate

Translate
Contributor ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

This is where you see my sheepish expression as I solve my own problem. For what it's worth, I'd love one of the gurus to explain "WHY", but here's the solution:

 

I was using "IS" between the two variables. When I changed IS to EQ and removed the quotes, all is well. 

 

So, this works as expected. With the variables holding the same value:

 

 

<cfif url.userid eq session.userid>

 

Could it be that I was comparing a numeric value with a text value?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Aug 06, 2021 Aug 06, 2021

Copy link to clipboard

Copied

Your original post shows that you're incorrectly comparing url.userid to the literal string "session.userid" rather than the value of session.userid, which you are correctly doing in your second post.

Remove the quotes from the example in your first post and it will behave the way you expect.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 07, 2021 Aug 07, 2021

Copy link to clipboard

Copied

LATEST

I agree with @EddieLotter . Another variation, likely the one you intended,  is:

<cfif url.userid is "#session.userid#"> <!--- Condition True --->

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation