Hello, I have written a Change Password Page script and it unfortunately does not seem to work. It displays "Your current password did not match what we have on file. Try again" whatever I do... Whether I send a form without completing the fields.. Whether I enter all fields correctly.. I don't know what's wrong with it.
<?
session_start();
if (!$_SESSION['idx'])
header("Location: index.php");
$id = $_SESSION['idx'];
$successMsg = "";
$errorMsg = "";
if ($_POST['parse'] == "passchange") {
$current_pass = $_POST['current_pass'];
$new_pass1 = $_POST['new_pass1'];
$new_pass2 = $_POST['new_pass2'];
if ($new_pass1 != $new_pass2) {
$errorMsg = 'Create New Password and Confirm New Password did not match.
<p><a href="settings.php">Try again</a></p>';
}
// Connect to database
include_once "ctm.php";
// Add MD5 Hash to the password variable
$hash_cur_pass = md5($current_pass);
$hash_new_pass = md5($new_pass1);
$sql = mysql_query("SELECT * FROM x WHERE id='$idx' AND password='$hash_cur_pass'");
$pass_check_num = mysql_num_rows($sql);
if ((!$current_pass) || (!$new_pass1) || (!$new_pass2)){
$errorMsg = 'Please fill in all fields';
}
if ($pass_check_num > 0) {
$sqlUpdate = mysql_query("UPDATE x SET password='$hash_new_pass' WHERE id='$id'");
$successMsg = 'Your password has been changed successfully.
<p><a href="profile.php">Click here to go to your profile</a></p>';
} else {
$errorMsg = 'Your current password did not match what we have on file.
<p><a href="change_pass.php">Try again</a></p>';
}
}
?>
Thanks in advance.