有困难与PHP忘记密码链接


Having difficulty with PHP forgotten password link

嗨,我有一个忘记的密码脚本,当用户点击电子邮件链接,它发送回密码重置页面。一旦点击,它就会进入所需的页面,但有一个问题,两个发送表单都出现了。我还有一个忘记密码的文件。如果你看过这张图,这就是即将出现的。我对PHP有点陌生。我只是想显示新密码和确认新密码的形式。

https://www.dropbox.com/s/y2qhxovodk3rlrv/2015-07-15_0814.png?dl=0

脚本:

<div class="container">
    <div class="row">
    <?php 
require_once 'connection.php';
if (isset($_GET['code'])) 
{
$get_username = $_GET['username'];
$get_code = $_GET['code'];
$query = mysqli_query($connection,"SELECT * FROM user_tbl WHERE username='$get_username'");
while ($row1s = mysqli_fetch_assoc($query)) 
{
 $db_code= $row1s['passreset'];
 $db_username= $row1s['username'];
}
if ($get_username == $db_username && $get_code == $db_code ) 
{
    echo "
    <form action='forgotpassword_process.php' method='post'>
            <legend><h1 style='color:red;'>Forgot Password</h1></legend><br>
            <div class='input-field col s6'>
                <div class='form-group'>
                    <span class='help-block'>Enter Your New Password</span>
                    <input type='password' name='newpass' class='form-control' placeholder='New Password '>
                </div>
            </div>
            <div class='input-field col s6'>
                <div class='form-group'>
                    <span class='help-block'>Re-Enter Your Password  </span><br>
                    <input type='password' name='password1' class='form-control' placeholder='Password'>
                </div>
            </div>

            <input type='submit' name='submit' class='btn' value='Update Password' />
            <input type='hidden' name='username' class='btn' value='$db_username' />

        </form>


    ";
    }

}

?>

    <form action="forgotpassword_process.php" method="post">
            <legend><h1 style="color:red;">Forgot Password</h1></legend><br>
            <div class="input-field col s6">
                <div class="form-group">
                    <span class="help-block">Enter your username</span>
                    <input type="text" name="username" class="form-control" placeholder="User Name">
                </div>
            </div>
            <div class="input-field col s6">
                <div class="form-group">
                    <span class="help-block">Enter your email </span><br>
                    <input type="text" name="email" class="form-control" placeholder="Password">
                </div>
            </div>

            <input type="submit" name="submit" class="btn" value="submit" />

        </form>
    </div>
</div>

在第二个表单之前,您可以添加else条件,如下所示

<div class="container">
    <div class="row">
    <?php 
require_once 'connection.php';
if (isset($_GET['code'])) 
{
  $get_username = $_GET['username'];
  $get_code = $_GET['code'];
  $query = mysqli_query($connection,"SELECT * FROM user_tbl WHERE username='$get_username'");
while ($row1s = mysqli_fetch_assoc($query)) 
{
 $db_code= $row1s['passreset'];
 $db_username= $row1s['username'];
}
if ($get_username == $db_username && $get_code == $db_code ) 
{
    echo "
    <form action='forgotpassword_process.php' method='post'>
            <legend><h1 style='color:red;'>Forgot Password</h1></legend><br>
            <div class='input-field col s6'>
                <div class='form-group'>
                    <span class='help-block'>Enter Your New Password</span>
                    <input type='password' name='newpass' class='form-control' placeholder='New Password '>
                </div>
            </div>
            <div class='input-field col s6'>
                <div class='form-group'>
                    <span class='help-block'>Re-Enter Your Password  </span><br>
                    <input type='password' name='password1' class='form-control' placeholder='Password'>
                </div>
            </div>

            <input type='submit' name='submit' class='btn' value='Update Password' />
            <input type='hidden' name='username' class='btn' value='$db_username' />
        </form>
    ";
    }
} else {
?>
    <form action="forgotpassword_process.php" method="post">
            <legend><h1 style="color:red;">Forgot Password</h1></legend><br>
            <div class="input-field col s6">
                <div class="form-group">
                    <span class="help-block">Enter your username</span>
                    <input type="text" name="username" class="form-control" placeholder="User Name">
                </div>
            </div>
            <div class="input-field col s6">
                <div class="form-group">
                    <span class="help-block">Enter your email </span><br>
                    <input type="text" name="email" class="form-control" placeholder="Password">
                </div>
            </div>

            <input type="submit" name="submit" class="btn" value="submit" />

        </form>
    </div>
</div>
<?php 
  } // end else 
?>