By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,854 Members | 833 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,854 IT Pros & Developers. It's quick & easy.

Split two different users on log in page

P: 63
Hi
I need to have two different users LOG in on to my page.Each of them have their own tables to where their data is stored and I have a separate users table which has username and password,then the username is suposed to link to the other two tables,I do register to each table then when using that data to LOGIN it doesnt work.

Is there a way I must do it.Here's my login code.The customer must see a different page from the supplier when logged on.

Thanx

<?php
$connection = mysql_connect("localhost", "root", "phpmysql");
$select_db = mysql_select_db("procdb", $connection);
$query = mysql_query ("SELECT cust_code, cust_username, cust_pswrd FROM customer", $connection);
$query = mysql_query ("SELECT supp_code, supp_email, supp_pswrd FROM supplier", $connection);


if(isset($_COOKIE['ID_my_site']))

//if there is, it logs you in and directes you to the members page
{
$name = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT cust_pswrd FROM customer WHERE cust_username = '$cust_username'")or die(mysql_error());
//$check = mysql_query("SELECT cust_username,cust_pswrd FROM customer WHERE cust_username = '$cust_username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pswrd != $info['cust_pswrd'])
{
}
else
{
header("Location: welcome.php");

}
}
}

//if the login form is submitted
if (isset($_POST['submit'])) { // if form has been submitted

// makes sure they filled it in
if(!$_POST['name'] | !$_POST['pass']) {
die('You did not fill in a required field.<a href=mysql_connection1.php>back</a>');
}
// checks it against the database

if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}

$check = mysql_query("SELECT cust_pswrd FROM customer WHERE cust_username = '".$_POST['name']."'")or die(mysql_error());
$check1 = mysql_query("SELECT supp_pswrd FROM supplier WHERE supp_name = '".$_POST['name']."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
$check3 = mysql_num_rows($check1);
//$check2 = mysql_num_rows($check1);

if ($check2 && $check3 == 0) {
die('That user does not exist in our database.

<a href=reg1.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['cust_pswrd'] = stripslashes($info['cust_pswrd']);
$info['supp_pswrd'] = stripslashes($info['supp_pswrd']);
$_POST['pass'] = md5($_POST['pass']);

//gives error if the password is wrong
if (($_POST['pass'] != $info['cust_pswrd'])|($_POST['pass'] != $info['supp_pswrd'])) {
//if (md5($_POST['pass'] ,$info['cust_pswrd'] ==$info['cust_pswrd'])){


//if ($_POST['pass']!= $info['cust_pswrd']) {
echo $_POST['pass']."<br>\n";
echo $_POST['$info']."<br>\n";
die('Incorrect password, please try again.<a href=mysql_connection1.php>Click Here </a>');
}
else
{

// if login is ok then we add a cookie
$_POST['name'] = stripslashes($_POST['name']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['name'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);

//then redirect them to the members area
$query = mysql_query ("SELECT supp_code, supp_email, supp_pswrd FROM supplier", $connection);
header("Location: welcome.php");
}
}
}
else
{

// if they are not logged in
?>

<TR>
<TD><IMG height=115 src="resources/visitorsBanner.png" width="100%"></TD>
</TR>
<form action="<?php echo $_SERVER['../test/PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td colspan=2><h1>Login</h1></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="name" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="50">
</td></tr>
<tr>
<td colspan="2" align="right"> <input type="submit" name="submit" value="Login">
<input type="Reset" value="Clear Form" ></td>
</tr>
<tr>
<td>
<a href=reg1.php>Customer Register</a>
<a href=reg2.php>Supplier Register</a>
</td>
</tr>
</table>
</form>

<?php
}

?>
Sep 11 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.