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"> 会员名:
<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 "原密码为 ".$info[true_pwd];?>');" class="a1">显示原密码</a></div></td>
</tr>
</table>
</body>
</html>
<?php
}else{
echo "<script>alert('提示答案或者邮箱地址输入错误!');history.back();</script>";
exit;
mysql_close($conn);
}
?>
运行后他总是提示该用户不存在
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"> 会员名:
<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 "原密码为 ".$info[true_pwd];?>');" class="a1">显示原密码</a></div></td>
</tr>
</table>
</body>
</html>
<?php
}else{
echo "<script>alert('提示答案或者邮箱地址输入错误!');history.back();</script>";
exit;
mysql_close($conn);
}
?>
运行后他总是提示该用户不存在
解决方案 »
- Notice: Undefined variable: submit in D:\phpnow\htdocs\web\title.php on line 5
- PHP连接数据库的问题
- 新手请教
- 请教在服务器上执行fsockopen无法响应的原因?
- 在用PHP和javaScirp做一个(下拉列表)多选择的程序,如何让一个文本框得到下拉列表的值呢?
- 为什么只能显示255个字符?(后续)
- 有没有检测数据库改动的好方法?
- 如何在php中向oracle数据库插入日期时间型数据?
- php获取IP及校验其所属网段的问题求助。急!跪谢!
- MYSQL数据库并发查询求教
- 请教关于json_encode的奇怪问题
- 急需php移动代码,求高手指点
$user哪儿来的?
$user = $_POST["tb_user"];
$sql = mysql_query("select * from lt_user where lt_user='".$user."'",$conn);
$info = mysql_fetch_array($sql);
$sql=mysql_query("select * from lt_user where lt_user='".$user."'",$conn);
$user是否应该是 $nc ,也没见你定义过$user
$sql=mysql_query("select * from lt_user where lt_user='".$user."'",$conn);
$user这个不对吧??
$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){
比对一下得出的数据
and???有这样写的么?
$email = trim($_POST["email]");
echo $da."<br/>";
echo $email."<br/>";看下是否是填写错了或者与数据库中不一致。
这样写也是可以的吧。
或者 &&
但我去数据库中浏览密保跟邮箱都对的
<input type="hidden" name="user" value="<?php echo $user;?>"> 检查getback_pass_ok.php 下的 $user
这些错误都是些小失误,稍微改改代码测试看看就能发现
也就是说打印出的结果应该不唯一么?查看数据库是不是有多个user$sql = "select * from lt_user where lt_user='".$user."'";
echo $sql;
吧这条sql语句到sql控制台执行,看有多少条记录