<?php 
Session_Start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理员登陆</title>
<script type="text/javascript">
   function changeImg()
   {
    document.getElementById("ValidateCodeIMG").src='code.php?'+Math.random();;
   }
</script> </head>
<body>
<?php 
if ($_GET["action"]=="login"){
$con = mysql_connect("xxx","xxx","xq6638089");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("sq_xqstudy", $con);
mysql_query("set names'utf8'");
$result = mysql_query("SELECT * FROM admin");
while($rs = mysql_fetch_array($result))
  { if ($rs["admin"]==$_POST["n"]||$rs["password"]==$_POST["p"])
  {
  echo "<script>window.alert('登陆成功')</script>";
echo "<script>window.location.href='manage.php'</script>"; //跳转到管理页
$_session["admin"]==$rs["admin"];
echo $rs["admin"];
  }
  else 
  {
  echo "<script>window.alert('账号或者密码错误');history.go(-1);</script>";
  }
}
}
else
{
?>
<form id="form1" name="form1" method="post" action="?action=login">
  <table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td>&nbsp;</td>
      <td>账号:</td>
      <td colspan="3"><input type="text" name="n" id="n" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>密码:</td>
      <td colspan="3"><input type="password" name="p" id="p" /></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>验证码:</td>
      <td colspan="2"><input name="code" type="text" id="code" size="6" />
      <a href="javascript:changeImg();" title="更换一张验证码图片">
<img src="code.php" alt="看不清,请换一张" name="ValidateCodeIMG" border="0" id="ValidateCodeIMG" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td colspan="2"><input type="submit" name="button" id="button" value="提交" />        <input type="reset" name="reset" id="reset" value="重置" /></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
<?php 
}
?>
//session 赋值 失败

解决方案 »

  1.   

    要大写$_SESSION["admin"]==$rs["admin"];
      

  2.   

    $_session["admin"]==$rs["admin"]; 赋值应该是$_SESSION["admin"]=$rs["admin"];
    还有 应该在跳转之前设置session
      

  3.   

    $result = mysql_query("SELECT * FROM admin");
    while($rs = mysql_fetch_array($result))
      { if ($rs["admin"]==$_POST["n"]||$rs["password"]==$_POST["p"])
      {
       $_SESSION["admin"]==$rs["admin"];
      echo "<script>window.alert('登陆成功')</script>";
    echo $_SESSION["admin"];
    //session还是没有值
      

  4.   


    $_SESSION["admin"]==$rs["admin"];你什么时候听说过==是赋值了的,多了个=