Undefined variable notice (PHP)
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index">PHP: &ldquo;Notice: Undefined variable&rdquo;  and &ldquo;Notice: Undefined index&rdquo;</a>  </p>
</blockquote>



<p>I have a member.php page which contains this piece of code:</p>

<pre><code>&lt;?php
    if (isset($_SESSION['teacherusername'])) 
    {
        $username = $_SESSION['teacherusername'];
    }
?&gt;
</code></pre>

<p>Now in the teacherlogin.php I use "include" to include the code from the member.php page. The problem I have is that if I open up the teacherlogin.php page, it gives me an undefined variable error stating: <code>
Notice: Undefined variable: username in ... on line 25</code></p>

<p>Why is it stating it is undefined because I have defined it in the member.php page?</p>

<p>Below is the code in the teacherlogin.php:</p>

<pre><code>&lt;?php
  // PHP code
  session_start(); 

    ini_set('display_errors',1); 
 error_reporting(E_ALL);

// connect to the database
include('connect.php');
include('member.php');

  /* check connection */
  if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    die();
  }

  // required variables (make them explciit no need for foreach loop)
  $teacherusername = (isset($_POST['teacherusername'])) ? $_POST['teacherusername'] : '';
  $teacherpassword = (isset($_POST['teacherpassword'])) ? $_POST['teacherpassword'] : '';
  $loggedIn = false;
  $active = true;

  if ($username){
      echo "You are already Logged In: &lt;b&gt;{$_SESSION['teacherforename']} {$_SESSION['teachersurname']}&lt;/b&gt; | &lt;a href='./teacherlogout.php'&gt;Logout&lt;/a&gt;";
  }
  else{

echo "Please Login";

}

?&gt;
</code></pre>
