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!

login page just not working in coldfusion

Status
Not open for further replies.

snivern

Programmer
Nov 30, 2003
9
US
I've been trying for two days to get this to work. I let dreamweaver write the code for me. The username and password that I enter in is in the database. but it keeps sending to the loginfailed page that I created. It never goes the loginsucceeded page.
 
Here is all the code for the page

<cfif IsDefined(&quot;FORM.textfield&quot;)>
<cfset MM_redirectLoginSuccess=&quot;clientsearch.cfm&quot;>
<cfset MM_redirectLoginFailed=&quot;no.cfm&quot;>
<cfquery name=&quot;dbquery&quot; datasource=&quot;register&quot;>
SELECT username,password FROM register WHERE username='#FORM.textfield#' AND password='#FORM.textfield2#'
</cfquery>
<cfif dbquery.RecordCount neq 0 >
<cftry>
<cflock scope=&quot;Session&quot; timeout=&quot;30&quot; type=&quot;Exclusive&quot;>
<cfset Session.MM_Username=FORM.textfield>
<cfset Session.MM_UserAuthorization=&quot;&quot;>
</cflock>
<cfif IsDefined(&quot;URL.accessdenied&quot;) AND false>
<cfset MM_redirectLoginSuccess=URL.accessdenied>
</cfif>
<cflocation url=&quot;#MM_redirectLoginSuccess#&quot; addtoken=&quot;no&quot;>
<cfcatch type=&quot;Lock&quot;><!--- code for handling timeout of cflock --->
</cfcatch>
</cftry>
</cfif>
<cflocation url=&quot;#MM_redirectLoginFailed#&quot; addtoken=&quot;no&quot;>

<cfelse>
<cfset MM_LoginAction=CGI.SCRIPT_NAME>
<cfif CGI.QUERY_STRING NEQ &quot;&quot;>
<cfset MM_LoginAction=MM_LoginAction & &quot;?&quot; & XMLFormat(CGI.QUERY_STRING)>
</cfif>
</cfif>
<title>index2</title>
<p>Please enter your login information below:</p>
<form action=&quot;<cfoutput>#MM_loginAction#</cfoutput>&quot; method=&quot;POST&quot; name=&quot;loginform&quot; id=&quot;loginform&quot;>
<table width=&quot;300&quot; height=&quot;160&quot; border=&quot;1&quot;>
<tr>
<th width=&quot;155&quot; scope=&quot;row&quot;>Username:</th>
<td width=&quot;155&quot;><input type=&quot;text&quot; name=&quot;textfield&quot;></td>
</tr>
<tr>
<th scope=&quot;row&quot;>Password:</th>
<td><input type=&quot;text&quot; name=&quot;textfield2&quot;></td>
</tr>
<tr>
<th scope=&quot;row&quot;>&nbsp;</th>
<td><input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;></td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp; </p>
<p>&nbsp;</p>
</form>
<p>&nbsp; </p>

<cfoutput></cfoutput><cfoutput></cfoutput>
 
You might want to check you datasource in your query.
<cfquery name=&quot;dbquery&quot; datasource=&quot;register&quot;>
SELECT username,password FROM register WHERE username='#FORM.textfield#' AND password='#FORM.textfield2#'
</cfquery>
Where you have &quot;register&quot; as your datasource you also have register as the table you are pulling the username and password fields from. I ran the same code on my server with a little modification make sure your table fields are correct also. Here it is:


<cfif IsDefined(&quot;FORM.textfield&quot;)>
<cfset MM_redirectLoginSuccess=&quot;clientsearch.cfm&quot;>
<cfset MM_redirectLoginFailed=&quot;no.cfm&quot;>
<cfquery name=&quot;dbquery&quot; datasource=&quot;IGNEW&quot;>
SELECT user,password FROM access WHERE user='#FORM.textfield#' AND password='#FORM.textfield2#'
</cfquery>
<cfif dbquery.RecordCount neq 0 >
<cftry>
<cflock scope=&quot;Session&quot; timeout=&quot;30&quot; type=&quot;Exclusive&quot;>
<cfset Session.MM_Username=FORM.textfield>
<cfset Session.MM_UserAuthorization=&quot;&quot;>
</cflock>
<cfif IsDefined(&quot;URL.accessdenied&quot;) AND false>
<cfset MM_redirectLoginSuccess=URL.accessdenied>
</cfif>
<cflocation url=&quot;#MM_redirectLoginSuccess#&quot; addtoken=&quot;no&quot;>
<cfcatch type=&quot;Lock&quot;><!--- code for handling timeout of cflock --->
</cfcatch>
</cftry>
</cfif>
<cflocation url=&quot;#MM_redirectLoginFailed#&quot; addtoken=&quot;no&quot;>

<cfelse>
<cfset MM_LoginAction=CGI.SCRIPT_NAME>
<cfif CGI.QUERY_STRING NEQ &quot;&quot;>
<cfset MM_LoginAction=MM_LoginAction & &quot;?&quot; & XMLFormat(CGI.QUERY_STRING)>
</cfif>
</cfif>
<title>index2</title>
<p>Please enter your login information below:</p>
<form action=&quot;<cfoutput>#MM_loginAction#</cfoutput>&quot; method=&quot;POST&quot; name=&quot;loginform&quot; id=&quot;loginform&quot;>
<table width=&quot;300&quot; height=&quot;160&quot; border=&quot;1&quot;>
<tr>
<th width=&quot;155&quot; scope=&quot;row&quot;>Username:</th>
<td width=&quot;155&quot;><input type=&quot;text&quot; name=&quot;textfield&quot;></td>
</tr>
<tr>
<th scope=&quot;row&quot;>Password:</th>
<td><input type=&quot;text&quot; name=&quot;textfield2&quot;></td>
</tr>
<tr>
<th scope=&quot;row&quot;> </th>
<td><input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Submit&quot;></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
</form>
<p> </p>
 
This is what jumps out at me in being where your problem is:

<cfif IsDefined(&quot;URL.accessdenied&quot;) AND false>
<cfset MM_redirectLoginSuccess=URL.accessdenied>
</cfif>

Actually, in the first line, &quot;cfif IsDefined(&quot;URL.accessdenied&quot;) AND false&quot;. What exactly is this supposed to mean? What is supposed to be &quot;False&quot;? Basically, you're saying &quot;If it's defined and has no definition.&quot; I think that CF is getting confused by this statement and setting the variable and redirecting to the &quot;Access Denied&quot; page.

Try dropping the &quot;AND false&quot; or coming up with a clearer IF statement. I think if you drop the &quot;AND false&quot;, it may work as it is.

Hope This Helps!

Ecobb
- I hate computers!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top