i am new to the PHP and i building a website which is mostly copied from diff sources and i want the user who had logged in to be displayed but it does not. here is my HTML for the page



if (!(isset($_SESSION['username']) && $_SESSION['username'] != '')) {

header ("Location: checklogin.php");



<!DOCTYPE html>

<title>MAP MY WAY</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

<meta name="description" content="Google Maps API V3: Custom Directions Panel" />
<meta name="keywords" content="final_project" />
<meta name="author" content="Zohaib Tasnim" />

 <script type="text/javascript"   
 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?      
<link href="style.css" type="text/css" rel="stylesheet" />

<!--to disable the enter key-->
<script type="text/javascript"> 

 function stopRKey(evt) { 
 var evt = (evt) ? evt : ((event) ? event : null); 
 var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null); 
 if ((evt.keyCode == 13) && (node.type=="text"))  {return false;} 

 document.onkeypress = stopRKey; 


 <div id="mapCanvas">&#160;</div>
 <div id="box">
    <a id="btns"> welcome <?php echo($_SESSION['username']); ?></a>
    <a id="btns" href="profile.html"> My Profile</a>
    <a id="btns" href="login.php"> logout</a>
    <p class="or">[OR]</p>
    <div class="directionInputs">
        <form action="address_insert.php" name="form2" method="post">
            <p><label>A</label><input type="text" value=""  name="loc_a" 
  id="dirSource" /></p>
            <p><label>B</label><input type="text" value="" name="loc_b" 
  id="dirDestination" /></p>
            <a href="#getDirections" id="getDirections">Get Directions</a>
            <a href="#reset" id="paneReset">Reset</a>
            <a id="btns"><input name="submit" class="btns" type="submit" value="Save       
  Address" /></a>

    <div id="directionSteps">
        <p class="msg">Direction Steps Will Render Here</p>
    <!--<a href="#toggleBtn" id="paneToggle" class="out">&lt;</a>-->
<script type="text/javascript" src="sample.js"></script> 

and checklogin.php is


 $host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="map_my_way"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form 

// To protect MySQL injection (more detail about MySQL injection)
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";

// Mysql_num_row is counting table row

// If result matched $username and $password, table row must be 1 row

// Register $username
$_SESSION['login'] = true;
$_SESSION['username'] = $username;

else {

echo "Wrong Username or Password";

You need session_start() at the top of all scripts that intend to use the session state, whether to read from or set it.
Adding session_start() to your checklogin.php should fix the problem.