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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

storing information in session

Status
Not open for further replies.

Manic

Programmer
Feb 28, 2001
343
GB
I have users logging into a site and I would like to store some details from the database in the session.

I am a complete newbie when it comes to sessions so I would also need the code for how to retrive this information.

the code that I am using at the moment is.

Code:
<%
  dim conn, strconn

  strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & _
        Server.MapPath("_users_.mdb")

  set conn = server.createobject("adodb.connection")
  conn.open strconn
    UserName = Replace(Request("Username"), "'", "''")
  	Password = Replace(Request("Password"), "'", "''")

  SQL = "SELECT * FROM my_users WHERE UserName = '" & UserName & "'" & _
        "AND Password ='" & Password & "'"
  set oRs = conn.Execute(SQL)
  
%>
  
<%
  If oRs.EOF then
    Response.Redirect("login2.asp")
  Else
    Session("ID") = "my_session" 'any word you'd like
	Response.Redirect("administration.asp")
  End If

  Set conn = Nothing
  Set oRs = Nothing
%>

Or if you could suggest a better way to do this that would be great.

Thanks in advance

Manic
-----------------------------
I've broken it again !!
-----------------------------
 
yeah that looks fine!

to retrieve the session variable just use

session("varname") or you can cast it to a local varaible if you want, but is not really needed.

one thing tho, is I always use adovbs.inc ( or asp or whatever) and this gives the vb constants required.

To carry the session over multiple pages you will need this adovbs file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top