ReeceSayer Posted November 23, 2011 Share Posted November 23, 2011 Hi, This ones stumped me a little as i've done this previously and it seemed to work fine: I have a form to add with two password boxes, the IDs are different as they should be but the type is the same: <form action="<?php echo $PHP_SELF;?>" method="post"> <p>New Password: <input type="password" id="newpassword" name="newpassword" /></p><br /> <p>Confirm Password: <input type="password" id="confirmpassword" name="confirmpassword" /></p><br /> <p><input type="submit" name="submit" value="submit"></p> </form> I have this code to check if they are both equal then md5 them and add them to the database: // Check if button name "submit" is active, do this if(isset($_POST['submit'])) { //variable to identify user $email = ($_SESSION['email']); //post variable from form $newpassword = $_POST['newpassword']; $password = $_POST['confirmpassword']; //if passwords are not equal if($password != $confirmpassword) { echo "The passwords do not match<br />"; //debugging - to see if they are equal or not - remove afterwards echo $password . "<br />"; echo $newpassword . "<br />"; } //if passwords are equal if($newpassword == $password) { //use md5 so they match when logging in $password = md5($password); $newpassword = md5($newpassword); $sql= "UPDATE users SET password='$newpassword' WHERE username='$email'"; $result = mysql_query($sql); if($result) { echo "Congratulations You have successfully changed your password"; } } } I've tried to explain my thinking as best i can in the code, the debugging part at the top shows that both values seem to be identical yet i'm being thrown into the not equal loop and they aren't adding to the database. Can anyone explain what i'm doing wrong here? I imagine its only minor but its thrown me. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/251651-operator-value-when-it-seems-to-be/ Share on other sites More sharing options...
unlishema.wolf Posted November 23, 2011 Share Posted November 23, 2011 Just look at your variables. $newpassword = $_POST['newpassword']; $password = $_POST['confirmpassword']; if($password != $confirmpassword) { echo "The passwords do not match<br />"; Quote Link to comment https://forums.phpfreaks.com/topic/251651-operator-value-when-it-seems-to-be/#findComment-1290620 Share on other sites More sharing options...
ReeceSayer Posted November 23, 2011 Author Share Posted November 23, 2011 Ahhhh Sh*t sorry for wasting your time Not a clue why i haven't already noticed that. Quote Link to comment https://forums.phpfreaks.com/topic/251651-operator-value-when-it-seems-to-be/#findComment-1290621 Share on other sites More sharing options...
unlishema.wolf Posted November 23, 2011 Share Posted November 23, 2011 lol it happens to the best of us Quote Link to comment https://forums.phpfreaks.com/topic/251651-operator-value-when-it-seems-to-be/#findComment-1290626 Share on other sites More sharing options...
HDFilmMaker2112 Posted November 23, 2011 Share Posted November 23, 2011 Also, you should probably be using an elseif on the second check. Quote Link to comment https://forums.phpfreaks.com/topic/251651-operator-value-when-it-seems-to-be/#findComment-1290649 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.