This code is supposed to let the user change their password by typeing into the form their username and their old password and then their new password and they need to confirm the new password but the page ends up not updateing the password it just says that the password is updated. What should i do about it?
<?php
// Connects to your Database
mysql_connect("localhost", "email", "qwe") or die(mysql_error());
mysql_select_db("email") or die(mysql_error());
//This code runs if the form has been submitted
if (isset($_POST['submit'])) {
//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['new_pass'] | !$_POST['new_pass2'])
{
die('You did not complete all of the required fields. Click your browsers back button to go back.');
}
// checks if the username is in use
if (!get_magic_quotes_gpc())
{
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$ucheck = mysql_query("SELECT username FROM users WHERE username = '$usercheck'") or die(mysql_error());
$ucheck2 = mysql_num_rows($ucheck);
//if the username does not exists it gives an error
if ($ucheck2 != 1) {
die('The username '.$_POST['username'].' you used does not exist please click <a href="add.php">here</a> to redgester');
}
// this makes sure both passwords entered match
if ($_POST['new_pass'] != $_POST['new_pass2'])
{
die('Your passwords did not match. ');
}
// here we encrypt the password and add slashes if needed
$_POST['new_pass'] = md5($_POST['new_pass']);
if (!get_magic_quotes_gpc())
{
$_POST['new_pass'] = addslashes($_POST['new_pass']);
}
// now we insert it into the database
$insert = "UPDATE users SET password = 'new_pass' WHERE username='username' AND password='pass'";
$add_member = mysql_query($insert);
?>
<h1>Password Changed</h1>
<p>You have sucsessfully changed your password - you may now <a href="/login.php">login</a>.</p>
<?php
}
else { ?>
<html>
<body alink="white" vlink="white" link="white" background="/img/hrlines2.png">
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0" style="color:white" align="center">
<tr bgcolor=#990033><td>Username:</td><td> <input type="text" name="username" maxlength="60"> </td></tr>
<tr bgcolor=#276B9A><td>Password:</td><td> <input type="password" name="pass" maxlength="10"> </td></tr>
<tr bgcolor=#990033><td>New Password:</td><td> <input type="password" name="new_pass" maxlength="10"> </td></tr>
<tr bgcolor=#276B9A><td>Confirm New Password:</td><td> <input type="password" name="new_pass2" maxlength="10"> </td></tr>
<tr bgcolor=#990033><td colspan=2 align="center"><input type="submit" name="submit" value="Change password"></td></tr>
</table>
</form>
</body>
</html>
<?php
} ?>