Jump to content

weird problem with two strings being equal


jeff5656

Recommended Posts

I want to compare something in the database with a POSTed string to see if they are equal:

$query = "SELECT * FROM `testbase` WHERE `id` = '".$id."' ";
$result = mysql_fetch_array(mysql_query($query)) or die(mysql_error());
echo $result['t3'];
echo "<br>";
echo $_POST['t3'];

 

When I do that I get this:

WBC 7 Hg 7 INR: 1.4 Cx:

WBC 7 Hg 7 INR: 1.4 Cx:

 

They look the same right?

 

But when I do this,

if($result['t3'] == $_POST['t3']) {
    echo "they are equal"

}
else {
echo "Not equal"
}

 

I get

Not equal.

 

But they sure look equal!!  Any ideas??

Link to comment
Share on other sites

If the data in your database was imported from a file, it probably has new-lines at the end of each value. You can confirm if it is the data in the table by removing the trim() from that side of the comparison. You should probably run an UPDATE query to TRIM() all the values in the table.

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.

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