Split two different users on log in page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mankolele
    New Member
    • Sep 2006
    • 63

    Split two different users on log in page

    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($_COOK IE['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("SE LECT cust_pswrd FROM customer WHERE cust_username = '$cust_username '")or die(mysql_error ());
    //$check = mysql_query("SE LECT cust_username,c ust_pswrd FROM customer WHERE cust_username = '$cust_username '")or die(mysql_error ());
    while($info = mysql_fetch_arr ay( $check ))
    {
    if ($pswrd != $info['cust_pswrd'])
    {
    }
    else
    {
    header("Locatio n: 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_conn ection1.php>bac k</a>');
    }
    // checks it against the database

    if (!get_magic_quo tes_gpc()) {
    $_POST['email'] = addslashes($_PO ST['email']);
    }

    $check = mysql_query("SE LECT cust_pswrd FROM customer WHERE cust_username = '".$_POST['name']."'")or die(mysql_error ());
    $check1 = mysql_query("SE LECT 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>C lick Here to Register</a>');
    }
    while($info = mysql_fetch_arr ay( $check ))
    {
    $_POST['pass'] = stripslashes($_ POST['pass']);
    $info['cust_pswrd'] = stripslashes($i nfo['cust_pswrd']);
    $info['supp_pswrd'] = stripslashes($i nfo['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_conn ection1.php>Cli ck 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_m y_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("Locatio n: 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>L ogin</h1></td></tr>
    <tr><td>Usernam e:</td><td>
    <input type="text" name="name" maxlength="40">
    </td></tr>
    <tr><td>Passwor d:</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>C ustomer Register</a>
    <a href=reg2.php>S upplier Register</a>
    </td>
    </tr>
    </table>
    </form>

    <?php
    }

    ?>
Working...