Jump to content

Operator value != when it seems to be ==


Recommended Posts



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>


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);
    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.



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • 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.