Click to See Complete Forum and Search --> : How to set up login to read from 2 databases?


jeromechiaro
03-10-2006, 12:24 AM
I need to enable my login function to read data from 2 different tables in my database, the discussion forum table and the customer table. Right now, visitors can only login as customers because the login function is setup to read from the customer table, and not both of the tables.

I had a few website developers do the site for me, so I have tried to learn some javascript tutorials; I have learned the basics, but I cannot seem to figure out how to do this. I think it has to do with an "or" function or "if, then" statement.

How can I set it up so that the username and password can be read from either of the tables?

The current setup is listed below:

<%
success=2

if request("logout")<>"logout" then
rs.open "Select * from tblusers where username ='" & request("txtUsername") & "' and userpassword='" & request("txtPassword") & "'",con,1,3
'rs.open "Select * from tblusers where username ='" & request("txtUsername") & "' and userpassword='" & request("txtPassword") & "'",con,1,3
'response.write "Select * from tblusers where username ='" & request("txtUsername") & "' and userpassword='" & request("txtPassword") & "' and userdate='' or userdate<='#" & date() & "#'"
'response.end
if not(rs.eof or rs.bof) then
success=1
session("userid")=rs("userid")
session("username")=rs("username")
session("fpswd")= request("txtPassword")
response.redirect "welcome.asp"
Else
session("username")=""
success=0
Call ClearCookies()
session.Abandon()
End if
rs.close
End if
%>

How can I make th login function read from tblForum_Members, under the columns M_username and M_password?

Thank you,

Jerome

chrismartz
03-10-2006, 07:48 PM
Do a join to the table all in the same sql query to the two different tables on the username and password.

jeromechiaro
03-10-2006, 08:42 PM
Thanks for the reply.

Im kinda new at website development, so I dont know how to do a join to the table with the same sql query.

Is there anyway you can show me an example, or write a quick sql line.

Thanks.

chrismartz
03-11-2006, 10:25 AM
Give me some of the table names and any column names that should be included.

jeromechiaro
03-11-2006, 04:42 PM
Hey Chris:

The tables and their respective columns are as follows:

tblusers
userid
username
userpassword

and

Forum_Members
member_id
m_username
m_password

Thanks for helping me out.

chrismartz
03-11-2006, 07:28 PM
SELECT
*
FROM
tblusers tmem
, Forum_Members fmem
WHERE
tmem.username ='" & request("txtUsername") & "'
AND
tmem.userpassword='" & request("txtPassword") & "'"
AND
fmem.m_username ='" & request("txtUsername") & "'
AND
fmem.m_password ='" & request("txtUsername") & "' Here I have verified that the user is in both tables and am pulling every field from both tables. Hopefully this helps.

jeromechiaro
03-12-2006, 01:16 PM
Hey Chris,

That query worked perfectly. Thanks for taking the time to help me out on this one.