Jump to content

Operator value != when it seems to be ==


ReeceSayer

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/251651-operator-value-when-it-seems-to-be/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.