$_SESSION showing defined and undefined when checked from an input form
<p>What I'm trying to do is show a two seperate divs in the same spot depending on if the $_SESSION is set. The form shows when no $_SESSION is noticed and the account info shows when there is a $_SESSION. whats happening is when I sign in and it all goes through it sends me to the same screen with the same form but when I refresh the browser the account info shows up replacing the form. Can anyone see why the exchange isn't going on when I initially sign someone in and the $_SESSION is set?</p>

<pre><code>$signedIn='&lt;h3 id="signedInHeader"&gt;Welcome &lt;/h3&gt;&lt;p&gt;&lt;a href="convenientaddaddress.php"&gt; Add Address &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="convenientaccountinfo.php"&gt; Account Info &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="convenientsignout.php"&gt; Sign Out &lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="convenientaddcreditcard.php"&gt; Add C Card &lt;/a&gt;&lt;/p&gt;';


    $form='&lt;form id="signInForm" method="POST" action="index.php"&gt;&lt;h3 id="formHeader"&gt;Sign Into Account&lt;/h3&gt;&lt;br/&gt;
    &lt;p id="pRegister"&gt;&lt;a id="register" href="convenientregisterpage.php"&gt; Register &lt;/a&gt;&lt;/p&gt;&lt;br/&gt;
    &lt;label&gt;Email Addr:&lt;/label&gt;&lt;input type="text" name="userEmail" id="email" size="15"/&gt;&lt;br/&gt;
    &lt;label&gt;Password:&lt;/label&gt;&lt;input type="password" name="password" id="password" size="15"/&gt;&lt;br/&gt;
    &lt;input type="submit" value="Sign In" id="formSubmit" name="submit"/&gt; &lt;/form&gt;';
$username='';
$username=$_SESSION['userName'];
if(!$username){
    $signedInForm=$form;
}
if(isset($username)){
    $signedInForm=$signedIn;

}  
$username="";
$email=$_POST['userEmail'];
$password=$_POST['password'];
if(isset($_POST['submit'])){
    if(empty($email) || empty($password)){
    $msg_to_user3="Fill in both fields";
    }
    else{
    $results=mysql_query("SELECT * FROM register WHERE userEmail='$email'");
   if (mysql_num_rows($results)==0)
       $msg_to_user3 ="No such User";
    else
    {
      while ($login_row = mysql_fetch_assoc($results))
      {
       $password_db = $login_row['password'];
       if ($password!=$password_db){
         $msg_to_user3 ="Password doesn't match";
       }
         if ($password_db!=$password)

        $msg_to_user2="&lt;a id='forgetpassword' href='convenientforgotpassword.php'&gt;Forget Password&lt;/a&gt;";

       else
       {

          $active = $login_row['active'];
          $userEmail = $login_row['userEmail'];
          if ($active==0)
             $msg_to_user3= "Activate account at ($userEmail) &lt;/p&gt;";

        else
          { 
        //assign session
      $_SESSION['userName']=$username;

      }


      }
      }
    }
       }
}
</code></pre>
