Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - redirect to 2 diff pages based on If else
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

redirect to 2 diff pages based on If else

 Post Reply Post Reply Page  <12
Author
elbeardo View Drop Down
Newbie
Newbie


Joined: 21 February 2005
Location: United Kingdom
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote elbeardo Quote  Post ReplyReply Direct Link To This Post Posted: 22 February 2005 at 4:03pm
just posted the code up here for a better view http://mysite.wanadoo-members.co.uk/robspages/login.htm

and the page it is redirected to if successful http://mysite.wanadoo-members.co.uk/robspages/successfulLogin.htm



Edited by elbeardo - 22 February 2005 at 4:12pm
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 22 February 2005 at 4:23pm
It's not pulling the value out of the database.

Set rsCheckuser = Nothing

Thats your culprit.  Your closing the object before finishing with the values.
Back to Top
elbeardo View Drop Down
Newbie
Newbie


Joined: 21 February 2005
Location: United Kingdom
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote elbeardo Quote  Post ReplyReply Direct Link To This Post Posted: 22 February 2005 at 4:36pm
Hmmm......... so where should i have the set rsCheckuser = nothing ?
would it go after all of this? or after the "if Lcase" line and before the response.redirect lines?

'redirect
        if LCase(rsCheckuser("type")) = "admin" then
        Response.Redirect "successfulLogin.asp?name=" & strusername
        else
        Response.Redirect("staffframe.asp")


-----------------------------
Ok disreguard that....
im getting the error "Item cannot be found in the collection corresponding to the requested name or ordinal." now on the " if Lcase" line again.
Im going to start crying soon!cheers


Edited by elbeardo - 22 February 2005 at 4:42pm
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 22 February 2005 at 4:42pm
You need to close and reset all objects before every page redirect.  Or alternativly, you could keep it in the same place but put the value in a variable so that you can call on it afterwards.

Basically all objects used must be set to nothing in every case where the page closes or changes.
Back to Top
dj1811 View Drop Down
Newbie
Newbie


Joined: 11 February 2005
Status: Offline
Points: 26
Post Options Post Options   Thanks (0) Thanks(0)   Quote dj1811 Quote  Post ReplyReply Direct Link To This Post Posted: 22 February 2005 at 7:13pm
<%
     Dim conn, rsCheckuser, sqlQuery
     Dim strPassword1, strPassword2, strType, strUsername
    
     Set conn = Server.CreateObject("ADODB.Connection")
     conn.open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Project.mdb") & ";"
    
     strUsername = Request.Form("formUsername")
     strPassword1 = Request.Form("formPassword")
     sqlQuery = "SELECT password, type FROM [user] WHERE username ='" & strUsername & "'"
 
     set rsCheckuser = conn.execute(sqlQuery)
    
     If NOT rsCheckuser.EOF Then
           strPassword2 = rsCheckuser.Fields("password")
           strType=LCase(rsCheckuser.Fields("type"))
     END IF
   
     rsCheckuser.Close
     conn.Close
     Set rsCheckuser=Nothing
     Set conn=nothing
 
     If strPassword1 = strPassword2 Then
           Session("passCorrect") = True
           If strType = "admin" then
                 Response.Redirect "successfulLogin.asp?name=" & strUsername
           Else
                 Response.Redirect "staffframe.asp"
           End If
     Else
          Session("passCorrect") = False
          Response.Redirect"failedLogin.html"
     End if
 
    
%>
 
Something like that maybe is what you are trying to ... this way does the same thing and is maybe a tiny bit simpler:
 
<%
     Dim conn, rsCheckuser, sqlQuery
     Dim strPassword, strType, strUsername
    
     Set conn = Server.CreateObject("ADODB.Connection")
     conn.open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Project.mdb") & ";"
    
     strUsername = Request.Form("formUsername")
     strPassword = Request.Form("formPassword")
     sqlQuery = "SELECT type FROM [user] WHERE username ='" & strUsername & "'" AND password='" & strPassword & "'"
 
     set rsCheckuser = conn.execute(sqlQuery)
    
     If rsCheckuser.EOF Then
           strType = LCase(rsCheckuser.Fields("type"))
     END IF
   
     rsCheckuser.Close
     conn.Close
     Set rsCheckuser=Nothing
     Set conn=nothing
 
     SELECT CASE strType
         CASE "admin"
              Session ("passCorrect") = True
              Response.Redirect "successfulLogin.asp?name=" & strUsername
         CASE ""
              Session ("passCorrect") = False
              Response.Redirect "failedLogin.html"
         CASE ELSE
              Session ("passCorrect") = True
              Response.Redirect "staffframe.asp"
     END SELECT
%>
 
That only works if there are no NULL or blank values in they [type] field.


Edited by dj1811 - 22 February 2005 at 7:39pm
Back to Top
elbeardo View Drop Down
Newbie
Newbie


Joined: 21 February 2005
Location: United Kingdom
Status: Offline
Points: 21
Post Options Post Options   Thanks (0) Thanks(0)   Quote elbeardo Quote  Post ReplyReply Direct Link To This Post Posted: 23 February 2005 at 5:17am
Seriously, thanks for your replies (and time)... 
I havent checked that last one as of yet but i found another way of doing the same thing which seems to work....
Would be good if i could get this way to work too though so i will get back to you all on this....
 
Much appreciated,
thanks,
rob


Edited by elbeardo - 23 February 2005 at 5:18am
Back to Top
 Post Reply Post Reply Page  <12

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.