hi, i have 2 different user ~which are admin and instructor ,the admin successfully log in to admin.page and it will showing their name ,the instructor login in to instructor.page will showing their namr also.hope can help thx!!

<form id="form1" name="form1" method="post" action="">
  <table width="280" height="66" border="2" cellpadding="2" cellspacing="2">
    <tr>
      <td width="111">&nbsp;</td>
      <td width="147"><label>
        <input type="text" name="user" id="user" />
      </label></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
        <input type="password" name="pass" id="pass" />
      </label></td>
    </tr>
  </table>
  <label>
    <input type="submit" name="Submit" id="Submit" value="Submit" />
  </label>
  <?php require_once('../../../Connections/admin_db.php'); 
  mysql_select_db("admin_db");


if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {

$username = $_POST['user'];
$password = $_POST['pass'];
//text field

$result = mysql_query("SELECT user_name FROM login WHERE user_name='$username' AND password='$password' ")
or die(mysql_error());


if(mysql_num_rows($result)) { //if exist
          echo "Welcome, $username";

}
}

//else
//header('location:edit_plo_pc.php');


?>
</form>

Try this

<form id="form1" name="form1" method="post" action="">
    <table width="280" height="66" border="2" cellpadding="2" cellspacing="2">
    <tr>
    <td width="111">&nbsp;</td>
    <td width="147"><label>
    <input type="text" name="user" id="user" />
    </label></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><label>
    <input type="password" name="pass" id="pass" />
    </label></td>
    </tr>
    </table>
    <label>
    <input type="submit" name="Submit" id="Submit" value="Submit" />
    </label>
    <?php require_once('../../../Connections/admin_db.php');
    mysql_select_db("admin_db");
     
     
    if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {
     
    $username = $_POST['user'];
    $password = $_POST['pass'];
    //text field
     
    $result = mysql_query("SELECT * FROM login WHERE user_name='$username' AND password='$password' ")
    or die(mysql_error());
     
     
    if(mysql_num_rows($result)) {
       $row = mysql_fetch_array($result);
       session_start();
       $_SESSION['abc123'] = $row['id'];
       header('location: main.php');
     
    }
    }
     
    //else
    //header('location:edit_plo_pc.php');
     
     
    ?>
    </form>

Then in main.php

<?PHP 
require_once('../../../Connections/admin_db.php');
    mysql_select_db("admin_db");
session_start();
$request  = mysql_query("SELECT * FROM login WHERE id='".$_SESSION['abc123']."'");
$row = mysql_fetch_array($request);
echo ' Username :'. $row['user_name'];

?>

If you want a fully created code contact me at jnicholls92@hotmail.co.uk

also to keep user login detail avalible in your config.php page put session_start();
this will allow you to use there id in anything.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.