0

我要做的是根据是否设置了 $_SESSION 在同一位置显示两个单独的 div。当没有注意到 $_SESSION 时,表单会显示,当有 $_SESSION 时,会显示帐户信息。发生的事情是当我登录并且一切都通过时,它会将我发送到具有相同表单的同一屏幕,但是当我刷新浏览器时,帐户信息会显示替换表单。当我最初登录某人并且设置了 $_SESSION 时,任何人都可以看到为什么交换没有进行吗?

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


    $form='<form id="signInForm" method="POST" action="index.php"><h3 id="formHeader">Sign Into Account</h3><br/>
    <p id="pRegister"><a id="register" href="convenientregisterpage.php"> Register </a></p><br/>
    <label>Email Addr:</label><input type="text" name="userEmail" id="email" size="15"/><br/>
    <label>Password:</label><input type="password" name="password" id="password" size="15"/><br/>
    <input type="submit" value="Sign In" id="formSubmit" name="submit"/> </form>';
$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="<a id='forgetpassword' href='convenientforgotpassword.php'>Forget Password</a>";

       else
       {

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

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

      }


      }
      }
    }
       }
}
4

1 回答 1

0

因为 $username 始终为空。你没有在任何地方设置它......

编辑

并不总是空的。但是你一直覆盖它。

于 2012-07-22T15:48:42.730 回答