...

View Full Version : login script question



centenial
06-20-2006, 10:46 PM
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?


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!

Fumigator
06-20-2006, 11:03 PM
You need to identify your tables and columns with identifiers (I forget the official name):


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>?";
}

centenial
06-20-2006, 11:16 PM
You need to identify your tables and columns with identifiers (I forget the official name):


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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum