Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Posts
    43

    Unanswered: how to redirect page

    how do you redirect from a login page according to security level in access. I have my login page which checks for valid username and password, but how would you redirect according to a number in my access database. Here is code from page:

    <%
    'here is the connection string
    'Set conn = server.createobject("adodb.connection")
    Set adoCon = Server.CreateObject("ADODB.Connection")
    'this connection uses JET 4 it is the prefered method of connecting to an access database
    'DSNtemp = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("login.mdb")
    'if you cant use JET then comment out the line above and uncomment the line below
    'DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("wwwroot/login.mdb")
    adoCon.Open "DSN=Employees"
    'conn.Open DSNtemp
    Set rsEmployees = Server.CreateObject("ADODB.Recordset")

    'here we are getting the info from the login form
    If InStr(Request.Form("uid"),"'") Then
    uid = Replace(Request.Form("uid"),"'"," ")
    Else
    uid = Request.Form("uid")
    End If
    If InStr(Request.Form("pwd"),"'") Then
    pwd = Replace(Request.Form("pwd"),"'"," ")
    Else
    pwd = Request.Form("pwd")
    End If

    'now we will querry the database for a match
    strSQL = "Select * From users Where uid = '" & uid & "' And pwd = '" & pwd & "'"
    rsEmployees.Open strSQL, adoCon

    'if the user is found we will set the session okeydokey to TRUE allowing the user to gain entrance
    If Not rsEmployees.EOF Then
    session("login") = "TRUE"
    session("loanofficer") = rsemployees("loanofficer")

    'always always always destroy recordsets and close connections!
    Set rsEmployees = Nothing
    Set rsEmployees= Nothing
    Set adoCon = Nothing

    'since the user was found, we sent them toodling on to the next page
    '################################################# ################################################## #####
    '##### IN THE LINE BELOW CHANGE INDEX2.ASP TO THE PAGE YOU WANT THE USERS TO BE DIRECTED TO
    Response.Redirect "search_form.asp"
    Else

    'ooops if we got this far they dont know their login info or arent in the database
    'AGAIN always always always destroy recordsets and close connections!
    Set rsEmployees = Nothing
    Conn.Close
    'so we send em back to try again
    Response.Redirect "index.asp"


    End If
    %>


    something like

    If blank = rs("field') then
    redirect blah.asp

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    do you mean something like this...?
    Code:
    <%
    Set adoCon = Server.CreateObject("ADODB.Connection")
    Server.Mappath("wwwroot/login.mdb")
    adoCon.Open "DSN=Employees"
    Set rsEmployees = Server.CreateObject("ADODB.Recordset")
    
    If InStr(Request.Form("uid"),"'") Then
      uid = Replace(Request.Form("uid"),"'"," ")
    Else
      uid = Request.Form("uid")
    End If
    
    If InStr(Request.Form("pwd"),"'") Then
      pwd = Replace(Request.Form("pwd"),"'"," ")
    Else
      pwd = Request.Form("pwd")
    End If
    
    'now we will querry the database for a match
    strSQL = "Select * From users Where uid = '" & uid & "' And pwd = '" & pwd & "'"
    rsEmployees.Open strSQL, adoCon
    
    If Not rsEmployees.EOF Then
      session("login") = "TRUE"
      session("loanofficer") = rsemployees("loanofficer")
      session("blank") = rsEmployees("field")
    
      'always always always destroy recordsets and close connections!
      Set rsEmployees = Nothing
      Set rsEmployees= Nothing
      Set adoCon = Nothing
      
      if session("blank") = 1 then
        Response.Redirect "search_form.asp"
      else if session("blank") = 3 then
        Response.Redirect "search_form3.asp"
      else
        Response.Redirect "search_form6.asp"
      end if
    
    Else
      Set rsEmployees = Nothing
      adoCon.Close
    'so we send em back to try again 
    Response.Redirect "index.asp"
    
    
    End If
    %>

  3. #3
    Join Date
    Oct 2004
    Posts
    43
    thats what I am looking for. I tried the code but get the error:

    Error Type:
    Microsoft VBScript compilation (0x800A03F6)
    Expected 'End'
    /database/check.asp, line 43
    Else

  4. #4
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    sorry,
    Code:
      if session("blank") = 1 then
        Response.Redirect "search_form.asp"
      elseif session("blank") = 3 then
        Response.Redirect "search_form3.asp"
      else
        Response.Redirect "search_form6.asp"
      end if
    you could also use a select case statement which might look nicer...

  5. #5
    Join Date
    Oct 2004
    Posts
    43
    worked thanks once again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •