jeff5656 Posted May 5, 2010 Share Posted May 5, 2010 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?? Quote Link to comment https://forums.phpfreaks.com/topic/200833-weird-problem-with-two-strings-being-equal/ Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 what do you get if you use if(trim($result['t3']) == trim($_POST['t3'])) { Quote Link to comment https://forums.phpfreaks.com/topic/200833-weird-problem-with-two-strings-being-equal/#findComment-1053813 Share on other sites More sharing options...
jeff5656 Posted May 5, 2010 Author Share Posted May 5, 2010 what do you get if you use if(trim($result['t3']) == trim($_POST['t3'])) { Hey now it says equal! Thanks. But why does that work. Was there an invisible carriage return in one? Quote Link to comment https://forums.phpfreaks.com/topic/200833-weird-problem-with-two-strings-being-equal/#findComment-1053817 Share on other sites More sharing options...
Muddy_Funster Posted May 5, 2010 Share Posted May 5, 2010 likely extra whitespace and/or special characters returned from the database. Quote Link to comment https://forums.phpfreaks.com/topic/200833-weird-problem-with-two-strings-being-equal/#findComment-1053819 Share on other sites More sharing options...
PFMaBiSmAd Posted May 5, 2010 Share Posted May 5, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/200833-weird-problem-with-two-strings-being-equal/#findComment-1053820 Share on other sites More sharing options...
jeff5656 Posted May 5, 2010 Author Share Posted May 5, 2010 Great, thanks guys. Quote Link to comment https://forums.phpfreaks.com/topic/200833-weird-problem-with-two-strings-being-equal/#findComment-1053833 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.