I\'ve created a page that allows users to change their password and email. All of it works but for some reason when I just want to change my email I also get the field Curre
You're checking that the post values are set for the password (which they always will be, because that form element will always be submitted). Instead of simplychecking if those vaues are set, make sure thay're not empty. use empty() Also, when making comparisons don't use the word "AND" use the and operator "&&".
if (!empty($_POST['repeatnewpassword']) && !empty($_POST['newpassword'])) {
if ($newpassword==$repeatnewpassword)
{
$querychange = mysql_query("UPDATE login SET password='$newpassword' WHERE username='$username'");
echo "
Password has been changed!";
}
else {echo "new password(s) dont match";}
}
I'm looking at the wrong chunk of code. The above advice is good advice, but your problem is here:
If the password fields are empty then these will never be the same, so if ($oldpassword==$oldpassworddb)
will always evaluate false.
Try
if ($oldpassword==$oldpassworddb && !empty($_POST['oldpassword']))