忘记密码功能不起作用,sql,php


Forgotpassword function not working, sql, php

不知道发生了什么,但它突然停止工作...我可以输入电子邮件和用户名(我知道凭据正确)并收到消息,指出它找不到任何匹配的详细信息......

忘记密码的内容.php:

<?php
require_once("users.inc");
$PAGE_TITLE = "Forgotten Password";
include $PHP_USERS_HEADER_FILE; 
?>
<h3>Forgot Your Password?</h3>
<p>If you've forgotten your password, just enter the username and email address that you registered with, and your password will be emailed to you immediately.</p>

<form method="post" action="emailpassword.php">
  <p><b>Your Username: </b>
  <input type="text" name="username" size="35" />
  </p><p>
  <b>Your Email Address: </b>
  <input type="text" name="email" size="35" />
  </p>
  <input type=submit value="Submit" />
</form>

邮箱密码的内容.php:

<?php
require_once("users.inc");
$PAGE_TITLE = "Forgotten Password";
connect_to_users_db();
$password = fnRandomPassword(8);
$encrypt_pwd = md5($password);
$sql = "UPDATE users SET password='$encrypt_pwd' WHERE email='".$_REQUEST['email']."' AND username='".$_REQUEST['username']."'";
$query = mysql_query($sql);
$sql1 = "SELECT email, username, password FROM users WHERE email='".$_REQUEST['email']."' AND username='".$_REQUEST['username']."'";
$query1 = mysql_query($sql1);
if ($query1 && (mysql_num_rows($query1) > 0)) {
  while (list($email,$username) = mysql_fetch_row($query1)) {
    mail($email, "Your Password", "Below is the username and password information you requested.'n'nUsername: '$username''nPassword: '$password'.'n'n","From: $WEB_MASTER <$WEB_MASTER_EMAIL>'n");
}
}

include $PHP_USERS_HEADER_FILE; 
?>
<h3>Forgot Your Password?</h3>
<?
echo "<p>";
//if ($query && mysql_num_rows($query) > 0) { 
if (mysql_affected_rows() > 0) { 
?>
<p>We've emailed your password. You should receive it within a minute. If you don't, please send mail to the <a href="mailto:<?=$WEB_MASTER_EMAIL?>"><?=$WEB_MASTER?></a>.</p>
<?php
} else { 
?>
<p>We could not find an email and username corresponding with the email address and username you entered. Perhaps you registered with a different email address/username. Use the form below to try again.</p>

<form method="post" action="emailpassword.php">
  <p><b>Your Username: </b>
  <input type="text" name="username" size="35" />
  </p><p>
  <b>Your Email Address:</b>
  <input type="text" name="email" size="35" />
  </p>
  <input type="submit" value="Submit" />
</form>

<p>If you believe you have not registered before, you are welcome to sign up now with the following form:</br>
      <?php include 'fragments/requestaccont.htm';?>
<?php
}
?>

这里有一些过时的编码或其他东西吗?

它停止工作,因为您更改了检查查询的行。现在,它将通过电子邮件发送新密码并显示"未找到"消息。

您正在使用mysql_affected_rows()但最后一个查询是不影响行的SELECT查询。更改行:

if (mysql_affected_rows() > 0) {

进入这一行:

if ($query1 && (mysql_num_rows($query1) > 0)) {

另请听杜恩,mysql_*已被弃用。