Php 登录在个人服务器上不起作用

Php 登录在个人服务器上不起作用,php,mysql,Php,Mysql,当我尝试登录时,显示“密码不正确”错误。但我知道它是正确的,因为它在我的服务器上。下面是与服务器上的登录机制交互的注册表 这是我的密码 <table width="300" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td> <form name="form1" method="post" action= "%3C?p

当我尝试登录时,显示“密码不正确”错误。但我知道它是正确的,因为它在我的服务器上。下面是与服务器上的登录机制交互的注册表

这是我的密码

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
    <tr>
      <td>
        <form name="form1" method="post" action=
        "%3C?php%20echo%20$_SERVER['PHP_SELF'];%20?%3E" id="form1">
          <table width="100%" border="0" cellpadding="3" cellspacing="1">
            <tr>
              <td colspan="3"><strong>Member Login</strong></td>
            </tr>

            <tr>
              <td width="78">Username</td>

              <td width="6">:</td>

              <td width="294"><input name="myusername" type="text" id=
              "myusername" /></td>
            </tr>

            <tr>
              <td>Password</td>

              <td>:</td>

              <td><input name="mypassword" type="password" id="mypassword" /></td>
            </tr>

            <tr>
              <td>&nbsp;</td>

              <td>&nbsp;</td>

              <td><input type="submit" name="Submit" value="Login" /></td>
            </tr>

            <tr>
              <td>&nbsp;</td>

              <td>&nbsp;</td>

              <td>
              <?php include( 'config.php'); // makes sure they filled it in if (isset($_POST[ 'Submit'])){ $username=$ _POST[ 'myusername']; $password=$ _POST[ 'mypassword']; $md5_pw=m d5($password); if($username==" " || $password=="" ) { echo( 'You did not fill in a required field.'); } else{ $query=m ysql_query( "SELECT *FROM admin
                                  WHERE user_name = '$username'  ")or die(mysql_error()); $query2=m ysql_num_rows($query); if ($query2==0 ) { echo( "That user does not exist in our database. <a     href=signup.php>Click Here to Register</a>"); } while($result=m ysql_fetch_array( $query )){ if($md5_pw !=$ result[ 'password']) { echo ( "incorrect password"); } else { session_start(); header( "Location: home.php"); } } } } ?></td>
            </tr>
          </table>
        </form>
      </td>
    </tr>
  </table>
</body>
</html>

会员登录
用户名
:
密码
:

您能帮我识别错误吗?

因为您总是收到
密码不正确的消息,即使输入的密码正确并且生成消息的代码如下

if($md5_pw != $result['password'])
{
    echo ("incorrect password");
}
很明显,
$md5_pw
$result['password']
的值在某种程度上是不同的。您可以通过添加
echo'md5:'来检查值。$md5_pw
echo数据库中的密码:'.$result['password']如下

echo 'md5: '.$md5_pw;
echo 'password in database: '.$result['password'];

if($md5_pw != $result['password'])
{
    echo ("incorrect password");
}

根据您的评论,
$result['password']
总是短两个字符,因此解决方案是更改数据库中
password
列的长度。

尝试添加
echo'md5:'。$md5\u pw
echo数据库中的密码:'.$result['password']
之前,如果($md5_pw!=$result['password'])
,则查看两者是否具有相同的值。是否将密码保存为数据库中的md5格式?确保将密码存储在数据库中的md5加密中。而且最好使用下面的查询
$query=mysql\u query(“选择*FROM admin,其中user\u name='$username'和password='$md5\u pw'))或die(mysql\u error())@ekad非常感谢。我做到了。是的,两个密码不同。数据库中密码始终缺少2个字符。这是因为数据库中的密码长度。现在我增加了。它的工作。