【发布时间】:2016-04-19 14:44:43
【问题描述】:
您好,我有一个注册表单,如果我点击忘记密码,我会收到邮件,如果我点击该链接,它会重定向到此处的更改密码页面我无法更新特定用户的密码。这是我的代码。发送忘记密码邮件时是否可以发送隐藏值的确认代码
发送邮件:我将通过此代码收到电子邮件。
$email=$_POST['email'];
if($_POST['submit']=='Send')
{
$query="select * from registered where email='$email'";
$result=mysql_query($query) or die(error);
if(mysql_num_rows($result))
{
$to = $_POST['email'];
$from .= 'mail@gmail.com' . "\r\n\r\n";
$subject="Password Change link here";
$message.="Click on this link to change your password \r\n";
$message.="http://website.com/accounting/changepassword.php?email=$email";
$success = mail($to, $subject, $message);
echo "Forgot Password link has been sent to your email.Check your email to change your password";
}
else
{
echo "No user exist with this email id";
}
}
link: Click on this link to change your password
http://website.com/accounting/changepassword.php?email=mail@gmail.com
如果我点击该链接,它将重定向到 forgetten.php 页面,我的代码是
但我无法更新密码,谁能帮助我。如果我单击该链接,它将从此处重定向到此页面,它将更改密码.php
更改密码.php
<form method="POST" action="forgotten.php" id="myform">
<input type='hidden' value="<?php echo $_GET['email'];?>" name='email'>
<div class="form-group">
<label for="psw"><span class="glyphicon"></span> Password</label>
<input id="password" class="form-control" type="password" name="password" placeholder="Enter password here" required/>
</div>
<div class="form-group">
<label for="rpsw"><span class="glyphicon"></span>Confirm Password</label>
<input id="repassword" class="form-control" type="password" name="repassword" placeholder="Retype password here" required/>
</div>
<button type="submit" class="btn btn-success btn-block"><span class="glyphicon glyphicon-off"></span> Create New Password</button>
forgetten.php 代码:
<?php
$connection = mysql_connect("localhost", "root", "account") or die(mysql_error());
$db = mysql_select_db("accounting", $connection);
$email=$_POST['email'];
$password=$_POST['password'];
$repassword=$_POST['repassword'];
$sql1="SELECT * FROM registered WHERE email ='$email'";
$result1=mysql_query($sql1);
$query = mysql_query("update registered SET password = '$password', repassword ='$repassword' WHERE email='$email'");
if($query)
{
$to = $_POST['email'];
$from .= 'mail@gmail.com' . "\r\n\r\n";
$subject="Password Changed";
$message.="your password has been changed successfully. \r\n";
$success = mail($to, $subject, $message);
echo "Password has been changed successfully";
}
else{
echo "Insertion Falied";
}
?>
【问题讨论】: