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 Topic: redirect to 2 diff pages based on If else
    Posted: 21 February 2005 at 8:21pm
hi ive searched all the forums etc and havent found an answer.

I'm using the asp login code and edited it to my own needs as im a propler newbie!
However, the example doesnt give an example of when you have in your database a "user type" field. This is for the type of user that logs in i.e admin or a normal user.
What i want it to do is if the user loging in is admin ,...they are redirected to one page and if the user is a normal user they are directed to another.
 I've tried this sql
"SELECT user.password, user.type FROM
user WHERE user.username ='" & strusername & "'"


basically all thats different here is that the "type" column is selected too. I then used this with:
'redirect
        IF rsCheckuser("type") = "admin" THEN
        Response.Redirect"successfulLogin.asp?name=" & strusername
        ELSE
        response.Redirect("staffframe.asp")
    END IF
    End IF
   
End If 

i know its either a really simple modification or ive got it completely wrong but ive spent sooo long on this i would be so grateful for any help.
ps - basically all ive changed are a few variables to fit in with my database, and the basic login and sessions worked fine with those.

btw if anyone want to help me out im ok if you use the original example coding and db.
rob


Edited by elbeardo - 21 February 2005 at 8:33pm
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post Posted: 21 February 2005 at 9:12pm

if LCase(rsCheckUser("type")) = "admin" then
Response.Redirect "successfulLogin.asp?name=" & strusername
else
Response.Redirect("staffframe.asp")
end if
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 7:48am
Thanks for the quick reply!
I'm not sure where the "LCase" comes from on that first line you gave me but i tried it anyway and the error its giving me is "Type mismatch" on that line. I think this was the same error i was getting before.
Also, is the way i queried the database to get the "type" record a valid way of doing this, or should it be queried separately?

thanks again so much for your help.
rob


Edited by elbeardo - 22 February 2005 at 7:49am
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 7:51am
Response.write the type and see what value it gives you
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 3:18pm
Try this,
 
"SELECT password, type FROM [user] WHERE username ='" & strusername & "'"
 
Also you should be careful when choosing names for your database so you do not use reserved words.  User is reserved.  I suggest you use use more unique names such as:
 
user_password, user_type and user_table to avoid using reserved words.
 
Also check if your recordset is empty before you check the password.  Otherwise you will get errors.
 
Like:
<%
IF rsCheckuser.EOF THEN
  'there was no match, go back to login screen
  Response.Redirect("login.asp")
ELSE
  'the code from above
  if LCase(rsCheckuser("type")) = "admin" then
    Response.Redirect "successfulLogin.asp?name=" & strusername
  else
    Response.Redirect("staffframe.asp")
  end if
END IF
%>
 
[EDIT: also watch the syntax so you do not switch from using rsCheckUser to rsCheckuser --  I'm fairly positive this is case sensitive.]


Edited by dj1811 - 22 February 2005 at 3:25pm
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 3:40pm
Ok i reverted back to my original one but still with the user.type in the query so i could check the result from Response.write of the type

"SELECT user.password, user.type FROM
user WHERE user.username ='" & strusername & "'"


The script works again (with no redirects for admin or normal users) but the Response.write(rsCheckuser("type")) or Response.write("type") dont seem to be giving me anything....not sure if this is due to the redirect for users to another asp page or what?!

Maybe it will be easier to look at if i post all the code for this
<%

Dim conn, rsCheckuser, filePath, sqlQuery, username, password, strusername

Set conn = Server.CreateObject("ADODB.Connection")
MdbFilePath = Server.MapPath("Project.mdb")
conn.open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"



strusername = Request.Form("formUsername")
password = Request.Form("formPassword")




sqlQuery = "SELECT user.password, user.type FROM user WHERE user.username ='" & strusername & "'"

'Query the database
set rsCheckuser = conn.execute(sqlQuery)


If NOT rsCheckuser.EOF Then

If (Request.Form("formPassword")) = rsCheckuser("password") Then

'If password correct then set the session variable to True
Session("passCorrect") = True

'Close Objects before redirecting
conn.Close
set conn = nothing
Set rsCheckuser = Nothing

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

End If

'Close Objects
conn.Close
set conn = nothing
Set rsCheckuser = Nothing

'non authorised
Session("passCorrect") = False

'Redirect to the unautorised user page

Response.Redirect"failedLogin.html"
%>

ps sorry about the layout of this code... i dont know how to get it looking pretty when posted


Edited by elbeardo - 22 February 2005 at 3:52pm
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 3:51pm
You probably don't have any values in the type column.  Open up the database and check if you do.
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 3:55pm
I've just checked again and i definitly do have values in the db type column.

again thanks for all your time everyone
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.