我照书上写的一个php会员登录的网页,主页可以打开,但跳转后总提示 Undefined variable
自己弄了1天了,该改的地方都改了,求助各位
具体错误代码如下:( ! ) Notice: Undefined variable: username in D:\wamp\www\myphp\chekmember.php on line 4 
Call Stack 
# Time Memory Function Location 
1 0.0004 368384 {main}( ) ..\chekmember.php:0 ( ! ) Notice: Undefined variable: userpasswd in D:\wamp\www\myphp\chekmember.php on line 4 
Call Stack 
# Time Memory Function Location 
1 0.0004 368384 {main}( ) ..\chekmember.php:0 
登录失败!请重新登录代码如下:
//member.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>会员登录</title>
</head><body>
<table width="36%" border="0" cellspacing+"1" cellpadding="1">
<form name="form1" method="post" action="chekmember.php">
  <tr>
    <td colspan="2"><div align="center">会员登录</div></td>
  </tr>
  <tr>
    <td width="34%" nowrap><div align="right">账号:</div></td>
    <td width="66%"><input name="username" type="text" id="username"></td>
  </tr>
  <tr>
    <td nowrap><div align="right">密码:</div></td>
    <td><input name="userpasswd" type="text" id="userpasswd"></td>
  </tr>
  <tr>
    <td colspan="2">
      <div align="center">
        <input type="submit" name="Sucmit" value="发送">
      </div>
    </td>
  </tr>
</form>
</table>
</body>
</html>//chekmember.php<?php
include "member_class.php";
$member=new member_class;
$adapt=$member->chkpasswd($username,$userpasswd);
if($adapt==true)
{
echo "您的账号为: ".$member->name;
echo "您的密码为: ".$member->passwd;
}else
{
echo "请重新登录";
}
?>
//member_class.php
<?php
class member_class
{
var $name="guan";
var $passwd="89473946";
var $adopt=false;
function chkpasswd($tname,$tpasswd)
{
if($tname==$this->name&&$tpasswd==$this->passwd)
{
echo  "通过登录!";
$this->adopt=true;
}else
{
echo  "登录失败!";
$this->adapt=false;
}
return $this->adapt;
}
}
?>

解决方案 »

  1.   

    //chekmember.php
    <?php
    include "member_class.php";
    $member=new member_class;
    $username = $_POST['username'];
    $userpasswd = $_POST['userpasswd'];  //加上这两行获取表单数据
    $adapt=$member->chkpasswd($username,$userpasswd); //问题在这一行,$username变量未定义
    if($adapt==true)
    {
        echo "您的账号为: ".$member->name;
        echo "您的密码为: ".$member->passwd;
    }else
    {
        echo "请重新登录";
    }
    ?>
      

  2.   

    不改代码的话,修改php.ini,重启Web服务。
    register_globals = On不过强烈不建议这么做,原因是:
      

  3.   

    这个我问题解决了,我看的是老版书,可以直接引用post过来的变量,由于涉及安全性问题,新的版本配置文件已经关掉这个了,只能使用$_POST['变量名']引用