cryptonim Posted February 9, 2011 Share Posted February 9, 2011 hi folks I have a problem with the code to change the password, it shows the message all time when I send the form: old password dont match! <?php session_start(); $user = $_SESSION['first_name']; if ($user) { //user is logged in if ($_POST['submit']) { //check fields $oldpassword = md5($_POST['oldpassword']); $newpassword = md5($_POST['newpassword']); $repeatnewpassword = md5($_POST['repeatnewpassword']); //check password against db //connect db $connect = mysql_connect("*******","****","****") or die(""); mysql_select_db("****") or die(""); $queryget = mysql_query("SELECT password FROM users WHERE username='$user'") or die("Query didnt work !!!"); $row = mysql_fetch_assoc($queryget); $oldpassworddb = $row['password']; //check password if ($oldpassword==$oldpassworddb) { //check to new password if ($newpassword==$repeatnewpassword) { //success //change password in db $querychange = mysql_query("UPDATE users SET password='$newpassword' WHERE username='$user'") or die (""); session_destroy(); die("YOUR PASSWORD HAS BEEN CHANGED.<a href='login_form.html'>RETURN</a> TO THE LOGIN PAGE"); } else die("new password dont match"); } else die("old password dont match"); } else { echo" <form action='changepassword.php' method='POST'> Old password: <input type='text' name='oldpassword'><br/> New password: <input type='password' name='newpassword'><br/> Repeat new password: <input type='password' name='repeatnewpassword'><br/> <input type='submit' name='submit' value='change password'> </form>"; } } else echo("YOU MUST BE LOGGED IN!!!!.<br><a href='login_form.html'>RETURN</a> TO THE LOGIN PAGE"); ?> please help thx! Link to comment https://forums.phpfreaks.com/topic/227159-change-password-problem-with-the-code/ Share on other sites More sharing options...
ChemicalBliss Posted February 9, 2011 Share Posted February 9, 2011 Put queries inside variables as you can echo them out indivdually to debug. Do this . Go through your code and echo variables at certain points to check and make sure they are what you expected. Since this condition is never true (as you always get that message): $oldpassword==$oldpassworddb then there is a problem with the DB or how you are interacting with it. hope this helps Link to comment https://forums.phpfreaks.com/topic/227159-change-password-problem-with-the-code/#findComment-1171919 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.