Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    login script question

    Hi,

    I have two tables in my MySQL database:
    1. companies
    2. employees

    Each table has some different fields, but they each have the three same login fields:
    1. email
    2. password
    3. company_admin (Has a value of either 1 or 0)

    I want to be able to use one login script for both types of users, and assign them a session value of 1 or 0 depending on whether they have "Company_Admin" powers.

    Here's what I have so far, but it keeps giving me a "Column 'email' in where clause is ambiguous" error - Can someone please help?

    Code:
    		include 'db.php';		
    		$check = "SELECT * FROM companies, employees WHERE email = '$_POST[email]' AND password = '$_POST[password]'";
    		$check_result = mysql_query($check,$conn) or die(mysql_error());
    
    		if (mysql_num_rows($check_result) > 0) {
    			while ($res = mysql_fetch_array($check_result)) {
    				$_SESSION[login_id] = $res['id'];
    				$_SESSION[company_admin] = $res['company_admin'];
    			}
    		header("Location: index.php");
    		exit;
    
    		} else {
    				$display_block = "We're sorry, but your login information appears to be incorrect. Would you like to <a href=\"$_SERVER[PHP_SELF]\">try again</a>?";
    		}
    Thanks!

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You need to identify your tables and columns with identifiers (I forget the official name):

    Code:
    		include 'db.php';		
    		$check = "SELECT * FROM companies cmpy, employees empl WHERE (cmpy.email = '$_POST[email]' AND cmpy.password = '$_POST[password]') OR
    (empl.email = '$_POST[email]' AND empl.password = '$_POST[password]')";
    		$check_result = mysql_query($check,$conn) or die(mysql_error());
    
    		if (mysql_num_rows($check_result) > 0) {
    			while ($res = mysql_fetch_array($check_result)) {
    				$_SESSION[login_id] = $res['id'];
    				$_SESSION[company_admin] = $res['company_admin'];
    			}
    		header("Location: index.php");
    		exit;
    
    		} else {
    				$display_block = "We're sorry, but your login information appears to be incorrect. Would you like to <a href=\"$_SERVER[PHP_SELF]\">try again</a>?";
    		}

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator
    You need to identify your tables and columns with identifiers (I forget the official name):

    Code:
    		include 'db.php';		
    		$check = "SELECT * FROM companies cmpy, employees empl WHERE (cmpy.email = '$_POST[email]' AND cmpy.password = '$_POST[password]') OR
    (empl.email = '$_POST[email]' AND empl.password = '$_POST[password]')";
    		$check_result = mysql_query($check,$conn) or die(mysql_error());
    
    		if (mysql_num_rows($check_result) > 0) {
    			while ($res = mysql_fetch_array($check_result)) {
    				$_SESSION[login_id] = $res['id'];
    				$_SESSION[company_admin] = $res['company_admin'];
    			}
    		header("Location: index.php");
    		exit;
    
    		} else {
    				$display_block = "We're sorry, but your login information appears to be incorrect. Would you like to <a href=\"$_SERVER[PHP_SELF]\">try again</a>?";
    		}
    The error is gone now, but it is assigning session values for a different user than the one supplied in the login form. Any idea why this is?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •