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??

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.

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.