I wanna showing the user name in every page when they are s successfully login to the page .But dun knoe why it cannot work~~


This is for login page ~~

<?php require_once('../../../Connections/admin_db.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
  session_start();
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "level";
  $MM_redirectLoginSuccess = "Index.php";
  $MM_redirectLoginFailed = "login.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_admin_db, $admin_db);
  	
  $LoginRS__query=sprintf("SELECT user_name, password, level FROM login WHERE user_name=%s AND password=%s",
  GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $admin_db) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
    
    $loginStrGroup  = mysql_result($LoginRS,0,'level');
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}

$currentPage = $_SERVER["PHP_SELF"];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--


Design by NodeThirtyThree <http://www.nodethirtythree.com>
Published by Free CSS Templates <http://www.freecsstemplates.org/>
Released for free under a Creative Commons Attribution 2.5 License

Title      : snowglass
Version    : 1.0
Released   : 20070718
Description: A two-column, fixed-width template featuring a blue glass effect ideal for 1024x768 resolutions.

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin-Program List</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="file:///C|/Users/shayfen/Desktop/snowglass/default.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#apDiv1 {
	position:absolute;
	width:651px;
	height:300px;
	z-index:1;
	left: 248px;
	top: 249px;
	background-color: #333333;
	border-top-style: solid;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: solid;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
	color: #FFF;
}
#apDiv2 {
	position:absolute;
	width:643px;
	height:26px;
	z-index:1;
	top: 6px;
	color: #FFF;
	font-size: 24px;
	text-align: center;
	border-top-style: groove;
	border-right-style: groove;
	border-bottom-style: groove;
	border-left-style: groove;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
	left: 3px;
	background-color: #666666;
}
#apDiv3 {
	position:absolute;
	width:595px;
	height:188px;
	z-index:2;
	left: 182px;
	top: 121px;
	background-color: #666666;
	border-top-style: double;
	border-right-style: double;
	border-bottom-style: double;
	border-left-style: double;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
	color: #666;
}
#apDiv4 {
	position:absolute;
	width:742px;
	height:44px;
	z-index:2;
	left: 212px;
	top: 268px;
}
.a {
	font-size: 18px;
}
.w {
	font-size: 14px;
}
#apDiv1 #apDiv3 table tr {
	border-top-style: solid;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: solid;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
	color: #000;
}
#apDiv1 #apDiv3 table tr {
	background-color: #FFF;
	color: #FFF;
}
#apDiv1 #apDiv3 table {
	font-family: Georgia, "Times New Roman", Times, serif;
	color: #999;
	background-color: #999;
}
-->
</style>
<style type="text/css">
<!--
#apDiv5 {
	position:absolute;
	width:382px;
	height:112px;
	z-index:3;
	left: 198px;
	top: 32px;
	background-color: #666666;
}
#apDiv1 #apDiv3 #apDiv5 #form1 table tr td {
	font-size: 18px;
}
#apDiv1 #apDiv3 #apDiv5 #form1 table tr td1 {
	color: #666;
}
#apDiv6 {
	position:absolute;
	width:604px;
	height:183px;
	z-index:3;
	left: 5px;
	top: 7px;
}
#apDiv1 #apDiv3 #form1 #apDiv6 table tr td {
	font-size: 18px;
}
#apDiv7 {
	position:absolute;
	width:573px;
	height:212px;
	z-index:2;
	left: 209px;
	top: 137px;
	background-color: #666666;
	color: #666;
}
#apDiv8 {
	position:absolute;
	width:337px;
	height:122px;
	z-index:1;
	left: 134px;
	top: 51px;
}
.j {
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
}
#apDiv9 {
	position:absolute;
	width:551px;
	height:207px;
	z-index:2;
	left: 422px;
	top: 196px;
	background-color: #33FF66;
	border-top-style: solid;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: solid;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
	font-size: 18px;
	text-align: center;
	color: #D6D6D6;
}
#apDiv1 #apDiv9 #form1 table trk {
	border-top-style: dotted;
	border-right-style: dotted;
	border-bottom-style: dotted;
	border-left-style: dotted;
	border-top-color: #D6D6D6;
	border-right-color: #D6D6D6;
	border-bottom-color: #D6D6D6;
	border-left-color: #D6D6D6;
}
#apDiv1 #apDiv9 #form1 table tr td {
	text-align: left;
}
#apDiv1 #apDiv9 #form3 table tr {
	border-top-style: solid;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: solid;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
}
#apDiv10 {
	position:absolute;
	width:527px;
	height:136px;
	z-index:3;
	left: 7px;
	top: 30px;
}
#apDiv1 #apDiv9 #form3 #apDiv10 table tr td {
	color: #FFF;
	font-size: 16px;
	font-weight: bold;
}
#apDiv1 #apDiv9 #p_list table {
	text-align: center;
}
#apDiv1 #apDiv9 #p_list a strongk {
	color: #FFF;
}
#apDiv1 #apDiv9 #p_list a strongo {
	color: #CCC;
}
body,td,th {
	color: #FFF;
	font-size: 14px;
	font-weight: bold;
}
#apDiv1 #apDiv9 #p_list a strong {
	background-color: #FFF;
}
.xx {
	font-family: Courier New, Courier, monospace;
}
#apDiv1 #apDiv9 #p_list table tr tdw {
	color: #F00;
}
a:link {
	color: #FFF;
	text-decoration: underline;
}
#apDiv11 {
	position:absolute;
	width:303px;
	height:59px;
	z-index:3;
	left: 225px;
	top: 246px;
}
body {
	background-color: #F4FFFF;
}
a:hover {
	color: #FF0;
	text-decoration: underline;
}
a:visited {
	text-decoration: underline;
}
a:active {
	text-decoration: underline;
}
#apDiv12 {
	position:absolute;
	width:648px;
	height:24px;
	z-index:3;
	left: 87px;
	top: 351px;
	color: #FF6;
	text-align: right;
}
#apDiv1 #apDiv12s {
	text-align: center;
}
#apDiv1 #apDiv12w {
	text-align: center;
}
.s {
	font-weight: bold;
	font-size: 14px;
}
#apDiv13 {
	position:absolute;
	width:163px;
	height:125px;
	z-index:2;
	left: -241px;
	top: -1px;
}
#apDiv14 {
	position:absolute;
	width:117px;
	height:134px;
	z-index:2;
	left: 71px;
	top: 88px;
}
#apDiv15 {
	position:absolute;
	width:354px;
	height:158px;
	z-index:3;
	left: 208px;
	top: 68px;
}
#apDiv1 #apDiv15 #passForm table tr td font5 {
	font-size: 16px;
}
#apDiv1 #apDiv15 #passForm table tr td fontu {
	font-size: 16px;
}
#apDiv1 #apDiv15 #passForm table tr td font6 {
	font-size: 16px;
}
#apDiv16 {
	position:absolute;
	width:342px;
	height:115px;
	z-index:3;
	left: 248px;
	top: 94px;
}
#apDiv17 {
	position:absolute;
	width:359px;
	height:143px;
	z-index:3;
	left: 229px;
	top: 91px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function savePass(nameusr,namepwd,valueusr,valuepwd,days) {
  var message = "";
  if (document.passForm.username.value == "" || document.passForm.password.value == "") {
    message = "Please insert both Username and Password.";
  }
  if (message.length > 0) {
    alert(message);
    return false;
  } else
  if (document.passForm.savepass.checked == true) {
    var time = new Date(Date.parse(Date()) + 86400000*days);
    document.cookie = nameusr + "=" + escape(valueusr) + "; expires=" + time.toUTCString();
    document.cookie = namepwd + "=" + escape(valuepwd) + "; expires=" + time.toUTCString();
  } else {
    document.cookie = nameusr + "=" + "" + "; expires=Thu,01-Jan-70 00:00:01 UTC";
    document.cookie = namepwd + "=" + "" + "; expires=Thu,01-Jan-70 00:00:01 UTC";
  }
}

function getCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg) {
      var endstr = document.cookie.indexOf(";", j);
      if (endstr == -1) endstr = document.cookie.length;
      return unescape(document.cookie.substring(j, endstr));
    }
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  }
  return "";
}

function getPass(nameusr,namepwd) {
  if (getCookie(namepwd) != "undefined" && getCookie(namepwd) != "") {
    document.passForm.username.value = getCookie(nameusr);
    document.passForm.password.value = getCookie(namepwd);
    document.passForm.savepass.checked = true;
  }
}
//-->
</script>
</head>
<body bgcolor="#D6D6D6">
<div id="header">
	<div id="logo"></div>
<img src="../images/img02.jpg" alt="" width="954" height="183" /></div>
<hr />
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="apDiv1" onload="getPass('cuser','cpass')">
  <div id="apDiv2"> &gt;&gt;User Login&lt;&lt;</div>
  <div id="apDiv14"><img src="../images/1300369977_preferences-desktop-user-password.png" alt="" width="110" height="132" /></div>
  <form method="post" id="passForm">
  </form>
  <div id="apDiv17" onload="getPass('cuser','cpass')">
<form ACTION="<?php echo $loginFormAction; ?>" method="POST" id="passForm">
      <table width="356" height="115" border="2" cellpadding="2" cellspacing="2">
        <tr>
          <td><font face="Arial" size="2">Username:</font></td>
          <td colspan="2"><input type="text" name="username" /></td>
        </tr>
        <tr>
          <td><font face="Arial" size="2">Password:</font></td>
          <td colspan="2"><input type="password" name="password" /></td>
        </tr>
        <tr>
          <td><font face="Arial" size="2">&nbsp;</font></td>
          <td><input name="savepass" type="checkbox" value="true" onclick="return savePass('cuser','cpass',username.value,password.value,30)" />
            <font face="Arial" size="1">Save Pass</font></td>
          <td align="right"><input type="submit" name="Submit" value="Enter" onclick="return savePass('cuser','cpass',username.value,password.value,30)" /></td>
        </tr>
      </table>
    </form>
  </div>
</div>
<p>&nbsp;</p> 
 <p>&nbsp;</p>
<p>&nbsp;</p>
<p>
  <!-- end page -->
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<hr />
</body>
</html>

This is the index page ~ the user successfully log in will direct come to this page and the page will showing their name

<?
// You may copy this PHP section to the top of file which needs to access after login.
session_start(); // Use session variable on this page. This function must put on the top of page.
//if(!session_is_registered("username")){ // if session variable "username" does not exist.
header("location:login.php"); // Re-direct to index.php
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--

Design by NodeThirtyThree <http://www.nodethirtythree.com>
Published by Free CSS Templates <http://www.freecsstemplates.org/>
Released for free under a Creative Commons Attribution 2.5 License

Title      : snowglass
Version    : 1.0
Released   : 20070718
Description: A two-column, fixed-width template featuring a blue glass effect ideal for 1024x768 resolutions.

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Admin-Program Register</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="file:///C|/Users/shayfen/Desktop/snowglass/default.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#apDiv1 {
	position:absolute;
	width:779px;
	height:353px;
	z-index:1;
	left: 213px;
	top: 274px;
	background-color: #333333;
	border-top-style: solid;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: solid;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
	color: #FFF;
}
#apDiv2 {
	position:absolute;
	width:769px;
	height:26px;
	z-index:1;
	top: 37px;
	color: #FFF;
	font-size: 24px;
	text-align: center;
	border-top-style: groove;
	border-right-style: groove;
	border-bottom-style: groove;
	border-left-style: groove;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
	left: 2px;
	background-color: #666666;
}
#apDiv3 {
	position:absolute;
	width:595px;
	height:188px;
	z-index:2;
	left: 182px;
	top: 121px;
	background-color: #666666;
	border-top-style: double;
	border-right-style: double;
	border-bottom-style: double;
	border-left-style: double;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
	color: #666;
}
#apDiv4 {
	position:absolute;
	width:724px;
	height:37px;
	z-index:2;
	left: 216px;
	top: 238px;
}
.a {
	font-size: 18px;
}
.w {
	font-size: 14px;
}
#apDiv1 #apDiv3 table tr {
	border-top-style: solid;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: solid;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
	color: #000;
}
#apDiv1 #apDiv3 table tr {
	background-color: #FFF;
	color: #FFF;
}
#apDiv1 #apDiv3 table {
	font-family: Georgia, "Times New Roman", Times, serif;
	color: #999;
	background-color: #999;
}
-->
</style>
<script src="../../../SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<link href="../../../SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
#apDiv5 {
	position:absolute;
	width:382px;
	height:112px;
	z-index:3;
	left: 198px;
	top: 32px;
	background-color: #666666;
}
#apDiv1 #apDiv3 #apDiv5 #form1 table tr td {
	font-size: 18px;
}
#apDiv1 #apDiv3 #apDiv5 #form1 table tr td1 {
	color: #666;
}
#apDiv6 {
	position:absolute;
	width:604px;
	height:183px;
	z-index:3;
	left: 5px;
	top: 7px;
}
#apDiv1 #apDiv3 #form1 #apDiv6 table tr td {
	font-size: 18px;
}
#apDiv7 {
	position:absolute;
	width:573px;
	height:212px;
	z-index:2;
	left: 209px;
	top: 137px;
	background-color: #666666;
	color: #666;
}
#apDiv8 {
	position:absolute;
	width:337px;
	height:122px;
	z-index:1;
	left: 134px;
	top: 51px;
}
.j {
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
}
#apDiv9 {
	position:absolute;
	width:528px;
	height:176px;
	z-index:2;
	left: 129px;
	top: 102px;
	background-color: #6699FF;
	border-top-style: solid;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: solid;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
	font-size: 18px;
	text-align: center;
}
#apDiv1 #apDiv9 #form1 table trk {
	border-top-style: dotted;
	border-right-style: dotted;
	border-bottom-style: dotted;
	border-left-style: dotted;
	border-top-color: #D6D6D6;
	border-right-color: #D6D6D6;
	border-bottom-color: #D6D6D6;
	border-left-color: #D6D6D6;
}
#apDiv1 #apDiv9 #form1 table tr td {
	text-align: left;
}
#apDiv1 #apDiv9 #form3 table tr {
	border-top-style: solid;
	border-right-style: solid;
	border-bottom-style: solid;
	border-left-style: solid;
	border-top-color: #FFF;
	border-right-color: #FFF;
	border-bottom-color: #FFF;
	border-left-color: #FFF;
}
#apDiv10 {
	position:absolute;
	width:527px;
	height:136px;
	z-index:3;
	left: 7px;
	top: 35px;
}
#apDiv1 #apDiv9 #form3 #apDiv10 table tr td {
	color: #FFF;
	font-size: 16px;
	font-weight: bold;
}
#apDiv1 #apDiv9 #form3 #apDiv10 table trs {
	background-color: #36C;
}
-->
</style>

</head>
<body>
<div id="header"></div>
<hr />
<p>&nbsp;</p>
<p>&nbsp;        </p>
<div id="apDiv1" onfocus="MM_validateForm('reg1','','R','p_state','','R');return document.MM_returnValue">
  <div id="apDiv2"> &gt;&gt;WELCOME !!!&lt;&lt;</div>
  <div id="apDiv9">
    <p></head>
<body>
<p>Hello <? echo $_SESSION['MM_Username']; ?>! You are now Logged in.</p>


  </div>
</div>
<div id="apDiv4">
  <ul id="MenuBar1" class="MenuBarHorizontal">
    <li><a class="MenuBarItemSubmenu" href="#">Program</a>
      <ul>
        <li><a href="p_list.php">Program List</a></li>
        <li><a href="p_reg.php">Program Register</a></li>
        <li><a href="#" class="MenuBarItemSubmenu">PEO </a>
          <ul>
            <li><a href="p_peo_reg.php">PEO Register</a></li>
            <li><a href="p_peo_reg.php">PEO List</a></li>
            <li><a href="#">PEO Map</a></li>
          </ul>
        </li>
<li><a href="#" class="MenuBarItemSubmenu">PLO </a>
  <ul>
    <li><a href="#">PLO Register</a></li>
    <li><a href="#">PLO Map</a></li>
    <li><a href="#">PLO Perforamnce Criteria</a></li>
    <li><a href="#">Untitled Item</a></li>
  </ul>
</li>
      </ul>
    </li>
    <li><a href="#" class="MenuBarItemSubmenu">Course</a>
      <ul>
        <li><a href="#">Course Register</a></li>
        <li><a href="#">Course List</a></li>
        <li><a href="#">CLO Register</a></li>
        <li><a href="#">CLO Map</a></li>
        <li><a href="#">CLO Perfomance Criteria</a></li>
      </ul>
    </li>
    <li><a class="MenuBarItemSubmenu" href="#">Instructor</a>
      <ul>
        <li><a class="MenuBarItemSubmenu" href="#">Instructor List</a>
          <ul>
            <li><a href="#">Item 3.1.1</a></li>
            <li><a href="#">Item 3.1.2</a></li>
          </ul>
        </li>
        <li><a href="#">Instructor Register</a></li>
</ul>
    </li>
    <li><a href="#" class="MenuBarItemSubmenu">Performance</a>
      <ul>
        <li><a href="#">By Instructor</a></li>
        <li><a href="#">By Program</a></li>
      </ul>
    </li>
    <li><a href="#">Log Out</a></li>
</ul>
</div>
<p>&nbsp;</p> 
 <p>&nbsp;</p>
<p>&nbsp;</p>
<p>
  <!-- end page -->
</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<hr />
<div id="footer">
  <p>&nbsp;</p>
  <p> (c) 2007 YourSite.com. All rights reserved. Design by <a href="http://www.nodethirtythree.com/">NodeThirtyThree</a> and <a href="http://www.freecsstemplates.org/">Free CSS Templates</a>.</p>
</div>
\<!--
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"../../../SpryAssets/SpryMenuBarDownHover.gif", imgRight:"../../../SpryAssets/SpryMenuBarRightHover.gif"});
//-->

</body>
</html>
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.