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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can i add can i do this, cause 1

Status
Not open for further replies.

maximos

Technical User
Sep 27, 2002
109
CA
Can i add

can i do this, cause its not going to the add.cfm

<!-- the part that i added --->
<cfif #session.userid# EQ &quot;admin&quot;>
<cfinclude template=&quot;add.cfm&quot;>
</cfif>
<!-- ends here --->
<cfif #session.userid# EQ &quot;max&quot;>
<cfquery name=&quot;table_member&quot; datasource=&quot;stock&quot;>
SELECT *
FROM tblmember
</cfquery>

<cfelse>
<cfquery name=&quot;table_member&quot; datasource=&quot;stock&quot;>
SELECT *
FROM tblmember
WHERE MemberName = '#session.userid#'
</cfquery>
</cfif>


what i want to do is , if admin logs in, i want him to go to a new page (the add.cfm page), the result i'm getting, as if that cfif statement deosn't exist, what am i doing wrong >?
Thanks for any input
Max Tadros
 
Have you outputed session.userid to the page to verify it's value?

DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
This is one of those problems that could be caused by one (or more) things... and not having your entire database here to see what you're actually doing, it's difficult to pinpoint your particular issue.

But... one of the more common issues that might be causing you problems is one of case-sensitivity. Values in ColdFusion are case-sensitive. Thus, &quot;Admin&quot; and &quot;ADMIN&quot; do not equal &quot;admin&quot;. For a case-insensitive compare, try something like:
Code:
<CFIF CompareNoCase(session.userid,&quot;admin&quot;)>
    <cfinclude template=&quot;add.cfm&quot;>
</CFIF>
Another tip would be to simply output the contents of session.userid right before your compare, just to make sure it contains what you're expecting it will:
Code:
<CFOUTPUT>#session.userid#</CFOUTPUT>
<CFIF CompareNoCase(session.userid,&quot;admin&quot;)>
    <cfinclude template=&quot;add.cfm&quot;>
</CFIF>
That will probably point you in a direction for a proper fix.


On a side note (again ;-) ) you can also use <CFSWITCH> rather than your <CFIF>s. Hard to tell... but if you see yourself adding more special cases (like &quot;max&quot;), a case statement is sometimes easier to maintain:
Code:
<CFSWITCH expression=&quot;#lcase(session.userid)#&quot;>
<CFCASE value=&quot;admin&quot;>
   <CFINCLUDE template=&quot;add.cfm&quot;>
   <CFEXIT>
</CFCASE>
<CFCASE value=&quot;max&quot;>
   <CFQUERY name=&quot;table_member&quot; datasource=&quot;stock&quot;>
      SELECT *
      FROM tblmember
    </CFQUERY>
</CFCASE>
      :
     add other cases for other values here
      :
<CFDEFAULTCASE>
   <CFQUERY name=&quot;table_member&quot; datasource=&quot;stock&quot;>
      SELECT *
      FROM tblmember 
      WHERE MemberName = '#session.userid#'
   </CFQUERY>
</CFDEFAULTCASE>
</CFSWITCH>

And, finally, if you're not using ColdFusion MX (and, in practice, even if you are using MX) you really want to make sure you use
Code:
<CFLOCK>
around every access to the SESSION, SERVER and APPLICATION scopes that you code. For this particular instance (because you'll more than likely need the CFEXIT) it's probably better to do a lock, and copy the value to a local variable, then check the value of that local variable. Something like:
Code:
<CFSET sLocalUserID = &quot;&quot;>
<CFLOCK timeout=&quot;10&quot; throwontimeout=&quot;No&quot; type=&quot;READONLY&quot; scope=&quot;SESSION&quot;>
   <CFSET sLocalUserID = session.userid>
</CFLOCK>

<CFSWITCH expression=&quot;#lcase(sLocalUserID)#&quot;>
<CFCASE value=&quot;admin&quot;>
   <CFINCLUDE template=&quot;add.cfm&quot;>
   <CFEXIT>
</CFCASE>
<CFCASE value=&quot;max&quot;>
   <CFQUERY name=&quot;table_member&quot; datasource=&quot;stock&quot;>
      SELECT *
      FROM tblmember
    </CFQUERY>
</CFCASE>
      :
     add other cases for other values here
      :
<CFDEFAULTCASE>
   <CFQUERY name=&quot;table_member&quot; datasource=&quot;stock&quot;>
      SELECT *
      FROM tblmember 
      WHERE MemberName = '#sLocalUserID#'
   </CFQUERY>
</CFDEFAULTCASE>
</CFSWITCH>



-Carl
 
Carl, That did the tric, the <CFSWITCH> tags, are way better, i got the cfif working, but it was displaying the template and the values on the same page, but the cfwitch worked way better,

I'll take a look at the cflock , ( i'm still a newbie )

But thanks alot anyways,

Max
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top