《php项目开发全程实录》第七章图书管理,管理员登录报错,
数据库已连通,从添加管理员页面能向数据库添加管理员。
管理员登录提示的错误是:您输入的管理员名称错误,请重新输入!
下面是登录页面的代码:(小妹刚开始学习看不明白哪里错了,这是明日科技的。最近明日科技网也打不开了。请前辈帮助看看先谢谢了)<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<head>
<title>学校图书馆管理系统</title>
<link href="CSS/style.css" rel="stylesheet">
<script language="javascript">
function check(form){
if (form.name.value==""){
alert("请输入管理员名称!");form.name.focus();return false;
}
if (form.pwd.value==""){
alert("请输入密码!");form.pwd.focus();return false;
}
}
</script>
</head>
<body>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<form name="form1" method="post" action="chklogin.php">
  <table width="100%"  border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="30%" bgcolor="86C1E6">&nbsp;</td>
      <td width="32%" background="Images/bg.gif"><table width="603" height="243"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolorlight="#FFFFFF" bordercolordark="#D2E3E6">
        <tr>
          <td width="50%" height="100" align="center">&nbsp;</td>
          <td width="50%">&nbsp;
          </td>
        </tr>
        <tr>
          <td height="90" rowspan="3" align="center">&nbsp;</td>
          <td height="30" valign="top">管理员名称:
            <input name="name" type="text" class="logininput" id="name3" size="25"></td>
        </tr>
        <tr>
          <td height="30" valign="top">管理员密码:
            <input name="pwd" type="password" class="logininput" id="pwd2" size="25"></td>
        </tr>
        <tr>
          <td height="30" align="center" valign="top"><input name="submit" type="submit" class="btn_grey" value="确定" onClick="return check(form1)">
&nbsp;
<input name="submit3" type="reset" class="btn_grey" value="重置">
&nbsp;
<input name="submit2" type="button" class="btn_grey" value="关闭" onClick="window.close();"></td>
        </tr>
        <tr>
          <td height="53" colspan="2" align="center"></td>
        </tr>
      </table></td>
      <td width="30%" bgcolor="86C1E6"><br></td>
    </tr>
  </table>
  <div align="center"><br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CopyRight  2007 www.mrbccd.com &nbsp;吉林***师范大学图书馆 </div>
</form>
</body>
</html>

解决方案 »

  1.   

    <?php
    session_start();
    $A_name=$_POST[name];          //接收表单提交的用户名
    $A_pwd=$_POST[pwd];            //接收表单提交的密码class chkinput{                //定义类
       var $name; 
       var $pwd;   function chkinput($x,$y){
         $this->name=$x;
         $this->pwd=$y;
        }   function checkinput(){
         include("conn/conn.php");      //连接数据源    
         $sql=mysql_query("select * from tb_manager where name='".$this->name."' and pwd='".$this->pwd."'",$conn);
         $info=mysql_fetch_array($sql);       //检索管理员名称和密码是否正确
         if($info==false){                    //如果管理员名称或密码不正确,则弹出相关提示信息
              echo "<script language='javascript'>alert('您输入的管理员名称错误,请重新输入!');history.back();</script>";
              exit;
           }
          else{                              //如果管理员名称或密码正确,则弹出相关提示信息
              echo "<script>alert('管理员登录成功!');window.location='index.php';</script>";
     $_SESSION[admin_name]=$info[name];
     $_SESSION[pwd]=$info[pwd];
       }
     }
    }
        $obj=new chkinput(trim($name),trim($pwd));      //创建对象
        $obj->checkinput();               //调用类
    ?>
      

  2.   

     $obj=new chkinput(trim($A_name),trim($A_pwd)); //创建对象
    改成上面试试
      

  3.   

    帮你稍稍修改了下代码。。自己慢慢调试去吧<?php
    error_reporting(E_ALL);//开启错误报告
    session_start();
    $A_name=htmlspecialchars(trim($_POST["name"])); //接收表单提交的用户名
    $A_pwd=htmlspecialchars(trim($_POST["pwd"])); //接收表单提交的密码class chkinput
    { //定义类
    var $name;
    var $pwd; function chkinput($x,$y){
    $this->name=$x;
    $this->pwd=$y;
    } function checkinput()
    {
    include("conn/conn.php"); //连接数据源

    //注意密码是否加密......
    $sql=mysql_query("select `name`,pwd from tb_manager where name='{$this->name}' and pwd='{$this->pwd}'") or die(mysql_error());
    $row=mysql_num_rows($sql); //检索管理员名称和密码是否正确
    if(!$row)

    //如果管理员名称或密码不正确
    return false;
    }
    else

    //如果管理员名称或密码正确
    $rs=mysql_fetch_array($sql);
    $_SESSION["admin_name"]=$rs["name"];
    $_SESSION["pwd"]=$rs["pwd"];
    return true;
    }
    }
    }
    $obj=new chkinput($A_name,$A_pwd); //创建对象
    $result=$obj->checkinput(); //调用类
    if ($result)
    {
    //登陆成功
    //some code here
    }
    else 
    {
    //登陆失败
    //some code here
    }?>
      

  4.   

    时间真快啊,我做的第一系统便是在此图书馆上改写的。很老了,技术也旧了,我用此系统骗过人。
    时间可真快。妹妹,你刚开始学,不建议使用OOP,你慢慢上路了再。还有就是登陆不上的话,你改成
     if($info==false){ 改成 if(0){