jamesxg1 Posted September 5, 2009 Share Posted September 5, 2009 Hiya Peeps, Heres my code. function ChangePassword($coldpassword, $cnewpassword, $ccnewpassword, $csaltv = "pepper925") { $password->salt = mysql_real_escape_string(trim(addslashes(strip_tags(sha1($csaltv))))); $password->old = mysql_real_escape_string(trim(addslashes(strip_tags(md5($coldpassword . $password->salt))))); $password->new = mysql_real_escape_string(trim(addslashes(strip_tags(md5($cnewpassword . $password->salt))))); $password->conf = mysql_real_escape_string(trim(addslashes(strip_tags(md5($ccnewpassword . $password->salt))))); $session->username = mysql_real_escape_string(trim(addslashes(strip_tags($_SESSION['username'])))); $session->id = mysql_real_escape_string(trim(addslashes(strip_tags($_SESSION['id'])))); print 'New: ' . $password->new . '<br> Conf: ' . $password->conf . '<br> Old: ' . $password->old . '<br><br>'; $passwordsql->checkpassword = "SELECT * FROM `members` WHERE username = '$session->username' AND id = '$session->id' AND password = '$password->old'"; $passwordsql->runcheckpassword = mysql_query($passwordsql->checkpassword) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); while($passwordmatch = mysql_fetch_array($passwordsql->runcheckpassword)) { if($password->new = $password->conf) { if($password->old = $passwordmatch['password']) { $passwordsql->changepassword = "UPDATE `members` SET password = '$password->new' WHERE username = '$session->username' AND id = '$session->id' AND password = '$password->old'"; $passwordsql->runchangepassword = mysql_query($passwordsql->changepassword) or trigger_error('Query failed: ' . mysql_error(), E_USER_ERROR); $passwordchangedone = 'Your password was sucessfully changed'; return ($passwordchangedone); } else { $passwordolddontmatch = 'Your old password does not match your current password please try again.'; return ($passwordolddontmatch); } } else { $passwordsdonotmatch = "Your new password doesnt not match the new password confirmation"; return ($passwordsdonotmatch); } } } I need to fix the if() statments because all they do is update the password and when i deliberately enter the password and confirm password wrong no error is displayed. Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/173238-for-some-reason-my-if-statments-arent-working/ Share on other sites More sharing options...
peranha Posted September 5, 2009 Share Posted September 5, 2009 All your if statements need to have == not just = == (equal to(compare 2 values)) = (sets a value to something) Quote Link to comment https://forums.phpfreaks.com/topic/173238-for-some-reason-my-if-statments-arent-working/#findComment-913182 Share on other sites More sharing options...
jamesxg1 Posted September 5, 2009 Author Share Posted September 5, 2009 You are very correct mate but i have no feedback. Either which way '=' or '==' they both are working for some reason. I have no error being displayed if i get the details correct all it does it change to password and return the successful message. Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/173238-for-some-reason-my-if-statments-arent-working/#findComment-913184 Share on other sites More sharing options...
mikesta707 Posted September 5, 2009 Share Posted September 5, 2009 no they are not working in the way you think. when the assignment operator (=) is in an if statement, it will assign the value of the right hand operand to the left hand operand and return true IE the following if ($i = 5){ // } Will assign $i with the value of 5, and return true because it successfully assigned the value of 5 to $i. However, you want to use the comparison operator (==), which will compare values. Right now your if statements assign the value of, for example, password->new to password->conf, in the following if statement if($password->new = $password->conf) this will always run true because it will succeed in assigning the value to the password->new variable. This won't return any errors because this is valid syntax. Sometmes you want to use the assignment operator in a boolean statement, like, for example, iterating through a mysql result with mysql_fetch_array, like in the following example $sql = mysql_query("Select * From table"); while($row = mysql_fetch_array($sql)){ //do stuff with data } but in your case you want to use the comparison operator Quote Link to comment https://forums.phpfreaks.com/topic/173238-for-some-reason-my-if-statments-arent-working/#findComment-913189 Share on other sites More sharing options...
jamesxg1 Posted September 5, 2009 Author Share Posted September 5, 2009 Hiya mate, Your logic is correct and i have changed the if statements to '==' but i still have no errors display when i have entered incorrect information. Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/173238-for-some-reason-my-if-statments-arent-working/#findComment-913190 Share on other sites More sharing options...
jamesxg1 Posted September 5, 2009 Author Share Posted September 5, 2009 Bump. Quote Link to comment https://forums.phpfreaks.com/topic/173238-for-some-reason-my-if-statments-arent-working/#findComment-913195 Share on other sites More sharing options...
jamesxg1 Posted September 5, 2009 Author Share Posted September 5, 2009 Does anyone know why this is happening ?, Many thanks, James. Quote Link to comment https://forums.phpfreaks.com/topic/173238-for-some-reason-my-if-statments-arent-working/#findComment-913198 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.