OriginalSunny Posted April 16, 2006 Share Posted April 16, 2006 Hi,I am creating a login page for an employee however the administrator should also be able to access the page. I have got it working for the employee to be able to access the page with a username and password using:[i] $sql = "SELECT Username FROM Employee WHERE Username='$_POST[username]'"; $result = mysql_query($sql) or die("Couldn't execute query."); $num = mysql_num_rows($result); if ($num == 1) // login name was found { $sql = "SELECT password FROM Employee WHERE Username='$_POST[username]' AND password='$_POST[password]'"; $result2 = mysql_query($sql) or die("Couldn't execute query 2."); $num2 = mysql_num_rows($result2); if ($num2 > 0) // password is correct ( .........................[/i]Now how do i alter it so that an administrator from the admin table can also access the page??I am thinking of using this but i know it wont work so there must be another way??[i] $sql = "SELECT Username FROM Employee [b]OR Admin[/b] WHERE Username='$_POST[username]'"; $result = mysql_query($sql) or die("Couldn't execute query."); ..............................[/i]The bit in bold is the bit i am supposed to be changing.Thanks. Quote Link to comment Share on other sites More sharing options...
arifsor Posted April 16, 2006 Share Posted April 16, 2006 [!--quoteo(post=365271:date=Apr 16 2006, 05:56 AM:name=OriginalSunny)--][div class=\'quotetop\']QUOTE(OriginalSunny @ Apr 16 2006, 05:56 AM) [snapback]365271[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi,I am creating a login page for an employee however the administrator should also be able to access the page. I have got it working for the employee to be able to access the page with a username and password using:[i] $sql = "SELECT Username FROM Employee WHERE Username='$_POST[username]'"; $result = mysql_query($sql) or die("Couldn't execute query."); $num = mysql_num_rows($result); if ($num == 1) // login name was found { $sql = "SELECT password FROM Employee WHERE Username='$_POST[username]' AND password='$_POST[password]'"; $result2 = mysql_query($sql) or die("Couldn't execute query 2."); $num2 = mysql_num_rows($result2); if ($num2 > 0) // password is correct ( .........................[/i]Now how do i alter it so that an administrator from the admin table can also access the page??I am thinking of using this but i know it wont work so there must be another way??[i] $sql = "SELECT Username FROM Employee [b]OR Admin[/b] WHERE Username='$_POST[username]'"; $result = mysql_query($sql) or die("Couldn't execute query."); ..............................[/i]The bit in bold is the bit i am supposed to be changing.Thanks.[/quote]Check this [code]SELECT USERNAME FROM EMPLOYEE E, ADMIN A WHERE E.USERNAME = $_POST['username'] OR A.USERNAME = $_POST['username'][/code]Arif Sorathia Quote Link to comment Share on other sites More sharing options...
OriginalSunny Posted April 17, 2006 Author Share Posted April 17, 2006 Tried this but it comes up with the error "couldnt execute query". $sql = "SELECT Username FROM Employee E, Admin A WHERE E.Username='$_POST[username]' or A.Username='$_POST[username]'"; $result = mysql_query($sql) or die("Couldn't execute query."); Any idea why?? 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.