I'm having an issue with coding a script that enables a logged in user to change his/her password. But when the form is submitted, a strange, blank page is displayed. There's no error message. Can you guys please, help me to resolve this issue? I'm not yet proficient in PHP and need all the insight I can get, to get my script to work fine. Here is the modifypass.php file:
<?php
// configuration
require("../includes/config.php");
// if form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
// validate submission
if (empty($_POST["curpassword"]))
{
apologize("You must provide your current password.");
}
else if (empty($_POST["newpassword"]))
{
apologize("You must enter a desired new password.");
}
else if (empty($_POST["confirmation"]))
{
apologize("You must confirm your new password.");
}
// query database for user
$rows = query("SELECT * FROM users WHERE username = ?", $_SESSION["id"]);
// if we found user, check password
if (count($rows) == 1)
{
// first (and only) row
$row = $rows[0];
// compare hash of user's input against hash that's in database
if (crypt($_POST["curpassword"], $row["hash"]) != $row["hash"])
{
apologize("You must provide your valid current password");
}
else if ($_POST["newpassword"] != $_POST["confirmation"])
{
apologize("Your new password and confirmation don't match.");
}
else if (query("UPDATE users SET hash = (?) WHERE username = (?)", crypt($_POST["newpassword"]), $_POST["username"]) === false)
{
apologize("Password update failed.");
}
else
{
// remember that user's now logged in by storing user's ID in session
$_SESSION["id"] = $row["id"];
// update the user's password to the new one
crypt($_POST["newpassword"], $row["hash"] = $row["hash"]);
// redirect to portfolio
redirect("/");
}
}
}
else
{
// else render form
render("modifypass-form.php", ["title" => "Reset Password"]);
}
?>
Here is the modifypass-form.php:
<div>
<a href="/">Home</a> | <a href="quote.php">Quote</a> | <a href="buy.php">Buy</a> | <a href="sell.php">Sell</a> | <a href="history.php">History</a> | <a href="logout.php">Sign Out</a> | <a href="resetpass.php">Modify Password</a>
</div>
<br/>
<br/>
<br/>
<form action="modifypass.php" method="post">
<fieldset>
<div class="form-group">
<input autofocus class="form-control" name="curpassword" placeholder="Current Password" type="password"/>
</div>
<div class="form-group">
<input class="form-control" name="newpassword" placeholder="New Password" type="password"/>
</div>
<div class="form-group">
<input class="form-control" name="confirmation" placeholder="Confirmation" type="password"/>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Modify Password</button>
</div>
</fieldset>
</form>
<div>
or <a href="register.php">register</a> for an account
</div>