尝试更新密码但我提交时没有任何反应

时间:2018-01-03 14:09:49

标签: php mysql sql

我正在尝试更新我的密码,但是当我按下提交按钮时,它只会清除这些框并且不会输出回复。

我仍然需要输入一个password_hash,但我认为它仍然应该输出一些东西。

编辑:完整代码,因为我不善于格式化:https://pastebin.com/HtEgsjZq

PHP     

session_start();

if(!isset($_SESSION['username']) || empty($_SESSION['username'])){
  header("location: login.php");
  exit;
}
if(isset($_POST["submit"]))
{

$newPassword = mysqli_real_escape_string($link, $_POST['newPassword']);
$confirm_password = mysqli_real_escape_string($link, 
$_POST['confirm_password']);
$username = mysqli_real_escape_string($link, $_SESSION['username']);

if ($newPassword != $confirm_password)
{
    echo "your passwords do not match";
}
else if ($newPassword == $confirm_password)
{
    $sql = mysqli_query($link, "UPDATE users SET password='$newPassword' 
    WHERE username='$username'");
    echo "You have successfully changed your password.";
}
else
{
    mysqli_error($link);
}
mysqli_close($link);
}
?>

HTML

<form action="<?php echo htmlspecialchars($_SERVER[" PHP_SELF "]); ?>" method="post">
<div class="form-group">

    <label for="newPassword">New Password</label>
    <input type="password" class="form-control" id="newPassword" placeholder="New Password" name="newPassword">
    <label for="confirm_password">Confirm New Password</label>
    <input type="password" class="form-control" id="confirm_password" placeholder="Confirm Password" name="confirm_password"> </div>
<div class="form-group">
    <input type="submit" class="btn btn-primary" value="Submit">
    <input type="reset" class="btn btn-default" value="Reset">
</div>
</div>
<p>
    <a href="welcome.php">Back to welcome page.</a>.</p>
</form>

0 个答案:

没有答案