zreon Posted June 23, 2007 Share Posted June 23, 2007 Hey all. I'm having a very difficult time figuring out how to get my login script to check 2 different tables for login details. Here is what my working code looks like right now to check 1 table. $db1=mysql_connect("$host", "$username", "$password")or die("cannot connect"); $db_select=mysql_select_db("$db_name", $db1)or die("cannot select DB"); $sql="SELECT * FROM $tbl_name WHERE firstname='$myusername' and buyer_email='$mypassword'"; $result=mysql_query($sql, $db1); I also need it to check this code. $sql="SELECT * FROM $tbl_name2 WHERE login='$myusername' and pass='$mypassword'"; $result=mysql_query($sql, $db1); Can I get any insight on how to do this? I'm sure it isn't that difficult and I have been searching for 3 days including looking in php books and searching. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 23, 2007 Share Posted June 23, 2007 query both individually and then use if($query1 == "true" && $query2 == "true"){//Login} Quote Link to comment Share on other sites More sharing options...
mmarif4u Posted June 23, 2007 Share Posted June 23, 2007 Did u have primary key in both tables to link together like id in both tables. If yes than u can do one query on id. Quote Link to comment Share on other sites More sharing options...
zreon Posted June 23, 2007 Author Share Posted June 23, 2007 Thanks for your quick responses although I'm not exactly sure what they mean. I am really really new with php and am amazed I even have a working login script up. This is how my code looks right now <?php ob_start(); $host="xxx"; // Host name $username="xxx"; // Mysql username $password="xxx"; // Mysql password $db_name="xxx"; // Database name $tbl_name="xxx"; // Table name $tbl_name2="xxx"; // Table name // Connect to server and select databse. $db1=mysql_connect("$host", "$username", "$password")or die("cannot connect"); $db_select=mysql_select_db("$db_name", $db1)or die("cannot select DB"); $sql="SELECT * FROM $tbl_name WHERE firstname='$myusername' and buyer_email='$mypassword'"; $result=mysql_query($sql, $db1); $sql="SELECT * FROM $tbl_name2 WHERE login='$myusername' and pass='$mypassword'"; $result=mysql_query($sql, $db1); As of right now, it will only check the second table for the information. Quote Link to comment Share on other sites More sharing options...
rcorlew Posted June 23, 2007 Share Posted June 23, 2007 You should use a 'Common' key (userid) or something to link the two tables together. Then you would use an join (left join or inner join) to match the two tables up. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.