• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

Conditional If Statement- Syntax Isse - Coldfusion

I have a cfif statement that is not functioning as I believed it was.  
astatus = blank
duserid = 12
session.uid = 12
qChkAuth.recordcount = 0
session.auth.userrole = 4

Minus qChkAuth.recordcount not being '1', all other conditons in the and (( "OR")) statement are satisfied. So I should fall into the first section of conditional if. But I am defaulting to the <cfesle>

What is wrong with my conditional statement?

<cfif (astatus is "") and ((#duserid# is #session.uid#) or (#qChkAuth.recordcount# is 1) or (#SESSION.Auth.Userrole# is 4))>

	<td  align="left"  valign="top"><a href="update2.cfm?rec_id=#drec_id#&control=#control_id#&location=#origin#"> 
	<strong><font face="Arial" color="blue" size="-1">#drec_id#</td>
	</font>
	Made it to admin level
<cfelse>
	<td  align="left" size="-1" valign="top"><a href="display1.cfm?rec_id=#drec_id#&location=#origin#"> 
	<strong><font face="Arial" color="blue" size="-1">#drec_id#</td>
	</font>
	not admin
</cfif>

Open in new window

0
mahpog
Asked:
mahpog
3 Solutions
 
_agx_Commented:
Maybe the values aren't what you think they are? Because it does produce the expected results using the values you supplied

<cfset astatus = "">
<cfset duserid = 12>
<cfset session.uid = 12>
<cfset qChkAuth.recordcount = 0>
<cfset session.auth.userrole = 4>

<cfif (astatus is "") and ((#duserid# is #session.uid#) or (#qChkAuth.recordcount# is 1) or (#SESSION.Auth.Userrole# is 4))>
	Made it to admin level
<cfelse>
	not admin
</cfif>

Open in new window


Print out the results of each comparison to see what's not matching the expected result

<cfoutput>
astatus[#astatus#] is "" = #(astatus is "")#<br> 
duserid[#duserid#] is session.uid[#session.uid #] = #(duserid is session.uid)#<br> or 
qChkAuth.recordcount[#qChkAuth.recordcount#] is 1 = #(qChkAuth.recordcount is 1)#<br> 
SESSION.Auth.Userrole [#SESSION.Auth.Userrole#] is 4 = #(SESSION.Auth.Userrole is 4)#<br>
</cfoutput>

Open in new window

0
 
gdemariaCommented:
no points..

 chances are it's your astatus field, perhaps it contains a space instead of empty?

 <cfif len(trim(astatus)) eq 0 and (.....)>

 
0
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
Hi!

Here is my Try

try This

<cfset isStatus = IsDefined("astatus") AND astatus EQ "">
<cfset isUserID = isDefined("duserid") AND duserid EQ 12>
<cfset isID = IsDefined("session.uid") AND session.uid EQ 12>
<cfset isRole = IsDefined("session.auth.userrole") AND session.auth.userrole EQ 4>
<cfset isCheck = isDefined("qChkAuth.recordcount") AND qChkAuth.recordcount EQ 0>

<cfif (isStatus AND (isUserID EQ isID)) OR (isCheck) OR isRole>
        Made it to admin level
<cfelse>
        not admin
</cfif>

Try Dumping each value and use it, it will work!

Cheers
0
 
mahpogAuthor Commented:
thank you all!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now