Stuck on PHP query

前端 未结 2 1150
梦毁少年i
梦毁少年i 2021-01-28 11:40

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

2条回答
  •  生来不讨喜
    2021-01-28 12:34

    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']))
    

提交回复
热议问题