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 <cfif url.userid is "session.userid"><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 <cfif url.userid is "session.userid"><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:
I'm stumped.
Thanks!
John Allred
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?
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?
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.
Copy link to clipboard
Copied
I agree with @EddieLotter . Another variation, likely the one you intended, is:
<cfif url.userid is "#session.userid#"> <!--- Condition True --->