mercredi 27 septembre 2017

PHP "if ($1 == $2)" comes out as false even though they are the same

I have created a website where you can login, atm im working on a page where you can change your password. So i have 3 <input> elements, 1 that checks that the "Current password" checks out (this one works fine) and the other 2 is "New Password" and "Confirm password" but when i put them into my if statment it comes out as false.

HTML form:

<input name="newpassword" type="password" placeholder="New password"/>
<input name="new2password" type="password" placeholder="Confirm password"/>

PHP code:

if ($newpassword == $new2password) {
  $newhash = password_hash($newpassword, PASSWORD_DEFAULT);

    $sql = "UPDATE users SET password = $newhash WHERE username = $username";

if ($conn->query($sql) === TRUE) {
    echo "Password successfully updated";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
}
} else {
  Echo "Passwords did not match";
}

Simplified:

if ($newpassword == $new2password) {
  Echo "Great success";
} else {
  Echo "Passwords did not match";
}

Any help to why this dosent work would be awesome.

Aucun commentaire:

Enregistrer un commentaire