我正在制作一个简单的忘记密码模块。 用户将输入他的用户名,安全问题答案和新密码。 因此,如果在数据库表中找到该用户,则密码将更新 否则它将显示错误。
FORM CODE:
<form id="fogform" method="POST">
<div class="form-group row">
<label for="un" class="col-form-label col-md-6">Username:
</label>
<div class="col-md-6">
<input type="text" class="form-control" name="un" placeholder="Enter your username" required>
</div>
</div>
<div class="form-group">
<div class="row">
<label class="col-form-label col-md-6" for="ques">Security
Question:</label>
<div class="col-md-6">
<select name="ques" class="form-control" required>
<option value="" selected>Choose any:</option>
<option value="In which city you were
born?">In which city you were born?
</option>
<option value="What was your first
pet's name?">What was your first pet's name?</option>
</select>
</div>
</div>
</div>
<div class="form-group row">
<label for="answ" class="col-form-label col-md-6">Your Answer:
</label>
<div class="col-md-6">
<input type="text" class="form-control" name="answ" placeholder="Enter your answer" required>
</div>
</div>
<div class="form-group row">
<label for="npwd" class="col-form-label col-md-6">New Password:
</label>
<div class="col-md-6">
<input type="password" class="form-control" name="npass" placeholder="Enter a New Password" required>
</div>
</div>
<div class="form-group row">
<label for="rpwd" class="col-form-label col-md-6">Retype Password:
</label>
<div class="col-md-6">
<input type="password" class="form-control" name="pass" placeholder="Retype the password" required>
</div>
</div>
<div class="form-group row">
<div class="col-md-5 offset-2">
<button type="reset" class="btn btn-danger">Reset</button>
</div>
<div class="col-md-5">
<button type="submit" name="fogo" class="btn btn-success" data-toggle="modal" data-target="#infomod" form="fogform">Submit</button>
</div>
</div>
</form>
PHP代码:
<?php
session_start();
$cn=mysqli_connect("localhost", "root", "", "imedtalks");
if(isset($_POST['fogo']))
{
$fogsql = "SELECT uname, passwd, que, ans FROM register WHERE passwd='".$_POST['pass']."'
AND que='".$_POST['ques']."' AND ans='".$_POST['ques']."' AND uname='".$_POST['un']."' ";
$rslt=mysqli_query($cn, $fogsql);
if($_POST['npass'] === $_POST['pass'])
{
if($row=mysqli_fetch_assoc($rslt))
{
$fogsql2 = "UPDATE register SET passwd='".$_POST['pass']."' WHERE que='".$_POST['ques']."' AND ans='".$_POST['ques']."'
AND uname='".$_POST['un']."' ";
if($cn->query($fogsql2) === TRUE)
{
echo " <script type='text/javascript'>alert('Password Reset Successful!')</script> ";
echo " <script type='text/javascript'>window.location.replace('http://localhost/PROII/HomePage.php')</script> ";
}
}
else
{
echo " <script type='text/javascript'>alert('Password Reset Unsuccessful! Try Again.')</script> ";
echo " <script type='text/javascript'>window.location.replace('http://localhost/PROII/HomePage.php')</script> ";
}
}
else
{
echo " <script type='text/javascript'>alert('Password Verification Failed! Try Again')</script> ";
echo " <script type='text/javascript'>window.location.replace('http://localhost/PROII/HomePage.php')</script> ";
}
}
?>
因此,在这里,每当我尝试使用错误的方式时,它都会给出不成功的消息,但是即使对于正确的字段数据,也会给出错误。 我是php的新手,这就是为什么我不明白它出了什么问题的原因。