coldfusion if/else confusion

dubstar

format c:
Joined
3 Dec 2002
Messages
1,357
My If/Else statement runs is connected to a variable that is created when you log-in. It is supposed to show a form to log-in when you're not logged in, or when 'Session.MM_Username' EQ "guest" . When you login, Session.MM_Username is what you enter in to the form (which is checked by the database of course) and this provides the key to unlock the menu, which replaces the form. Problem is, it keeps thinking "guest" is the name of the user and never shows the form.

is there a better way to go about this??

-- ignore the "check_name" query. it's from a previous attempt at getting this to work properly.


if i can get this working, i should be fine,
I've got cfparam name="Session.guest" default="guest"
and when you log out,
Code:
<cftry>
	<cflock scope="Session" type="exclusive" timeout="30">
		<cfset Session.MM_Username="guest">
		<cfset Session.MM_UserAuthorization="">
	</cflock>
	<cflocation url="index.cfm" addtoken="no">
	<cfcatch type="lock">
	<!-- code for handling timeout of cflock -->
	</cfcatch>

main section i need to work::
Code:
<cfif "Session.MM_Username" EQ "Session.guest">

		<form name="login" action="<cfoutput>#MM_loginAction#</cfoutput>" method="POST">
	  	<input name="userid" type="text" size="13" />
		<input name="userid_required" type="hidden" required="yes" message="Please enter your user name." /><br />
		<input name="password" type="password" size="13" />
		<input name="password_required" type="hidden" required="yes" message="Please enter your password." /><br />
		<input type="submit" value="-  login  -" /><br /><br />
		</form>
<cfelse>
	Hi, <cfoutput>#Session.MM_Username#</cfoutput><br /><br />
</cfif>



full code::
Code:
<cfparam name="Session.MM_Username" default="guest">
<cfparam name="Session.guest" default="guest">
<cfparam name="failed_login" default="false">
<cfif IsDefined("FORM.userid")>
  <cfset MM_redirectLoginSuccess="index.cfm">
  <cfset MM_redirectLoginFailed="index.cfm?failed_login=true">
  <cfquery  name="MM_rsUser" datasource="nerd_a_day">
    SELECT userid,password 
	FROM LoginInfo 
	WHERE userid='#FORM.userid#' 
	AND password='#FORM.password#'
  </cfquery>
  <cfif MM_rsUser.RecordCount NEQ 0>
    <cftry>
      <cflock scope="Session" timeout="30" type="Exclusive">
        <cfset Session.MM_Username=FORM.userid>
        <cfset Session.MM_UserAuthorization="">
      </cflock>
      <cfif IsDefined("URL.accessdenied") AND false>
        <cfset MM_redirectLoginSuccess=URL.accessdenied>
      </cfif>
      <cflocation url="#MM_redirectLoginSuccess#" addtoken="no">
      <cfcatch type="Lock">
        <!--- code for handling timeout of cflock --->
      </cfcatch>
    </cftry>
  </cfif>
  <cflocation url="#MM_redirectLoginFailed#" addtoken="no">
  <cfelse>
  <cfset MM_LoginAction=CGI.SCRIPT_NAME>
  <cfif CGI.QUERY_STRING NEQ "">
    <cfset MM_LoginAction=MM_LoginAction & "?" & XMLFormat(CGI.QUERY_STRING)>
  </cfif>
</cfif>

<cfquery datasource="#primaryDataSource#" name="check_name">
SELECT userid
FROM LoginInfo
</cfquery>

<cfif "Session.MM_Username" EQ "Session.guest">

		<form name="login" action="<cfoutput>#MM_loginAction#</cfoutput>" method="POST">
	  	<input name="userid" type="text" size="13" />
		<input name="userid_required" type="hidden" required="yes" message="Please enter your user name." /><br />
		<input name="password" type="password" size="13" />
		<input name="password_required" type="hidden" required="yes" message="Please enter your password." /><br />
		<input type="submit" value="-  login  -" /><br /><br />
		</form>
<cfelse>
	Hi, <cfoutput>#Session.MM_Username#</cfoutput><br /><br />
</cfif>
<a href="index.cfm">nerd word</a><br />
<a href="search_terms.cfm">search terms</a> <br />
<a href="see_all_terms.cfm">see all terms</a><br />
<a href="faq-help.cfm">faq/help</a><br /><br />
<span class="menu_ext">
<cfif NOT IsDefined( "Session.MM_Username" )>			
	<a href="sign_up.cfm">sign-up</a>
<cfelse>
	<a href="add_term.cfm">add a term</a><br />
	<a href="profile.cfm?profile=<cfoutput>#Session.MM_Username#</cfoutput>&edit_profile=true">edit your profile</a><br />
	<a href="logoff.cfm">log-off</a>
</cfif>
</span>
 
Last edited:
changing
Code:
<cfif "Session.MM_Username" EQ "Session.guest">

to

Code:
<cfif Session.MM_Username EQ "guest">

worked. sorry for the waste of space.

the Session.MM_Username didnt need quotes. grr.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,623
Latest member
AndersonLo
Back