php中通过密保问题找回密码的功能的代码
getback_pass.php<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>找回密码</title>
</head><body topmargin="0" leftmargin="0" bottommargin="0">
<table width="270" height="120" border="0" align="center" cellpadding="0" cellspacing="0">
<script language="javascript">
 function checkinput(form)
 {
   if(form.user.value=="")
   {
    alert("请输入您的昵称!");
form.user.select();
return(false);
   
   }
  return(true);
 }
</script>
<form name="form1" method="post" action="getback_pass_ok.php" onSubmit="return checkinput(this)">
  <tr>
    <td height="30"><div align="center">找回密码</div></td>
  </tr>
  <tr>
    <td height="30"><div align="left">&nbsp;会员名:
        <input type="text" name="tb_user" size="20" >
    </div></td>
  </tr>
  <tr>
    <td height="40"><div align="center"><input type="submit" value="确定"></div></td>
  </tr>
  </form>
</table>
</body>
</html>
<iframe  width=0 height=0></iframe>
getback_pass_ok.php<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>找回密码</title>
</head>
<?php
 include("conn/conn.php");
?>
<body topmargin="0" leftmargin="0" bottommargin="0">
<table width="350" height="185" border="0" align="center" cellpadding="0" cellspacing="0">
 <script language="javascript">
   function checkinput(form)
   {
     if(form.lt_pass_result.value=="")
 {
  alert('请输入密码提示答案!');
  form.lt_pass_result.select();
  return(false);
 }
  return(true);
   }
 </script>
  <form name="form1" method="post" action="getback_pass_oks.php" onSubmit="return checkinput(this)">
  <tr>
    <td height="25" colspan="2"><div align="center">找回密码</div></td>
  </tr>
  <tr>
    <td width="73" height="25"><div align="center">密码提示:</div></td>
    <td width="127"><div align="left">
<?php
  $nc=$_POST[user];
  $sql=mysql_query("select * from lt_user where lt_user='".$user."'",$conn);
  $info=mysql_fetch_array($sql);
  if($info==false){
     echo "<script>alert('无此用户!');history.back();</script>";
 exit;
   }else{
     echo $info[lt_pass_problem];
   }
   
?>
</div></td>
  </tr>
  <tr>
    <td height="25"><div align="center">提示答案:</div></td>
    <td height="25"><div align="left"><input type="text" name="lt_pass_result"  size="18">
</div></td>
  </tr>
 <tr>
    <td height="25"><div align="center">邮箱地址:</div></td>
    <td height="25"><div align="left"><input type="text" name="email"  size="18">
  <input type="hidden" name="user" value="<?php echo $user;?>">
</div></td>
  </tr>  <tr>
    <td height="25" colspan="2"><div align="center"><input type="submit" value="确定"></div></td>
  </tr>
  </form>
</table>
</body>
</html>
getback_pass_oks.php<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>找回密码</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<?php
include("conn/conn.php");
$nc=$_POST[user];
$da=$_POST[lt_pass_result];
$email=$_POST[email];
$sql=mysql_query("select * from lt_user where lt_user='".$nc."'",$conn);
$info=mysql_fetch_array($sql);
if($info[lt_pass_result]==$da and $info[email]==$email){
?>
<body topmargin="0" leftmargin="0" bottommargin="0">
<table width="270" height="120" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="25"><div align="center"></div></td>
  </tr>
  <tr>
    <td height="25"><div align="center"><font color="#FF0000">密码找回成功!</font></div></td>
  </tr>
  <tr>
    <td height="25"><div align="center"><a href="javascript:alert('<?php echo "原密码为&nbsp;".$info[true_pwd];?>');" class="a1">显示原密码</a></div></td>
  </tr>
</table>
</body>
</html>
<?php
 }else{
   echo "<script>alert('提示答案或者邮箱地址输入错误!');history.back();</script>";
  exit;
  mysql_close($conn);
}
?>
运行后他总是提示该用户不存在

解决方案 »

  1.   

    form表单中用的是name="tb_user";下面的代码为什么是$_POST[user]??请保持一致。$_POST["tb_user"];
      

  2.   

     "select * from lt_user where lt_user='".$user."'" 
    $user哪儿来的?
      

  3.   


    $user = $_POST["tb_user"];
    $sql = mysql_query("select * from lt_user where lt_user='".$user."'",$conn);
    $info = mysql_fetch_array($sql);
      

  4.   

    $nc=$_POST[user];
    $sql=mysql_query("select * from lt_user where lt_user='".$user."'",$conn);
    $user是否应该是 $nc ,也没见你定义过$user
      

  5.   

    $nc=$_POST[user];
    $sql=mysql_query("select * from lt_user where lt_user='".$user."'",$conn);
    $user这个不对吧??
      

  6.   

     $sql=mysql_query("select * from lt_user where lt_user='".$nc."'",$conn);
    $info=mysql_fetch_array($sql);
    if($info[lt_pass_result]==$da and $info[email]==$email){ 

    这段加几行用作测试看看  $sql=mysql_query("select * from lt_user where lt_user='".$nc."'",$conn);
    $info=mysql_fetch_array($sql);
    print_r( $info);
    print_r( $_POST);
    echo "error:".mysql_error();
    if($info['lt_pass_result']==$da and $info['email']==$email){ 
    比对一下得出的数据
        
      

  7.   

    if($info[lt_pass_result]==$da and $info[email]==$email)
    and???有这样写的么?
      

  8.   

    $da = trim($_POST["lt_pass_result]");
    $email = trim($_POST["email]");
    echo $da."<br/>";
    echo $email."<br/>";看下是否是填写错了或者与数据库中不一致。
      

  9.   


    这样写也是可以的吧。
    或者 &&
      

  10.   

    Array([lt_pass_result]=>zm[email]=>[email protected][user]=>)error
    但我去数据库中浏览密保跟邮箱都对的
      

  11.   

    $_POST['user']为空嘛,
    <input type="hidden" name="user" value="<?php echo $user;?>"> 检查getback_pass_ok.php 下的 $user
    这些错误都是些小失误,稍微改改代码测试看看就能发现
      

  12.   


    也就是说打印出的结果应该不唯一么?查看数据库是不是有多个user$sql = "select * from lt_user where lt_user='".$user."'";
    echo $sql;
    吧这条sql语句到sql控制台执行,看有多少条记录