简体   繁体   中英

how to combine two different queries?

When a user hits log in button on a page in order to verify heres what i need to do:

1st check if they exist and their login info is valid in the members table.

2nd using the entered username now check if they have access to this speficif page by checking the access table with their username.

i have to tables members and access.

Members has the following: id, username, password

Access has the following: userid, companyid

So say my username= ASH and password= 14ash
I'm trying to login to view a specific restricted page for the company called TARGET.

I first login with my account info with username ASH & password 14ash in php i check the database table called members with mysql to see if i exist

and at the sometime i check the ACCESS table using access.userid = ASH & access.companyid= TARGET

once all is check if i exist in both tables then i let the user login.

I tried this but doesn't work.

$sql="SELECT * FROM access,members 
WHERE members.username='$myusername'
 AND members.password='".md5($mypassword)."') 
OR (access.userid=members.username 
AND access.companyid='$username')";

它应该是

sql="SELECT * FROM access,members WHERE members.username='$myusername'AND members.password='".md5($mypassword)."' AND access.userid=members.id";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM