PDA

View Full Version : How do login if there is two tables in database


scriptblur
09-11-2002, 08:07 AM
Hi there,

Any kind souls can help me???:(

Example i got two table names in the database... Student and Staff in Login.dbm... i had already know how to login with one table name using SQL statement(below). But if i got 2 table names in one database... how to interact????
Like when i login as student it will interact with the student table in the database and proceed... or if I login as staff, it will interact with the staff table in the database and proceed. Thank u...




<%@ Language=VBScript %>
<% Option Explicit %>
<%
Dim conn,rs,sql
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("login.mdb"))

set rs=Server.CreateObject("ADODB.Recordset")


sql = "SELECT * FROM Staff WHERE UserID = '" & Request.Form("UserID") &"' AND Password = '" & Request.Form("Password") &"'"

rs.Open sql,conn

If rs.EOF Then
Response.Redirect "Failed.asp"
else
Response.Redirect "content.htm"
End If

%>

Morgoth
09-11-2002, 02:25 PM
Well, I think the best way tyo do it, is search for the username and password for the first table, then if it isn't there, search the second table.

If the
So..


<%@ Language=VBScript %>
<% Option Explicit %>
<%
Dim conn,rs,sql
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("login.mdb"))

set rs=Server.CreateObject("ADODB.Recordset")


sql = "SELECT * FROM Staff WHERE UserID = '" & Request.Form("UserID") &"' AND Password = '" & Request.Form("Password") &"'"

rs.Open sql,conn

If rs.EOF Then

rs.Close sql,conn

sql = "SELECT * FROM Student WHERE UserID = '" & Request.Form("UserID") &"' AND Password = '" & Request.Form("Password") &"'"

rs.Open sql,conn

If rs.EOF Then
Response.Redirect "Failed.asp"
Else
Response.Redirect "STUDENTcontent.htm
End If

Else
Response.Redirect "STAFFcontent.htm"
End If

%>


I help?

scriptblur
09-12-2002, 01:43 AM
Oh.. its work.. thank u...:)

Morgoth
09-12-2002, 03:08 AM
Np, glad I could help!