jaxdevil Posted October 21, 2008 Share Posted October 21, 2008 Something is wrong in my if statement, somehow. I below is the top of the function (the whole thing is way to big to post, but its this one section that is a problem) <? $q = "SELECT * FROM shipto_database WHERE shipto_code = '0000001' LIMIT 1"; $res = mysql_query($q); while ($row = mysql_fetch_array($res)) { $shipto_saddressx = $row["shipto_saddress"]; echo $shipto_saddress; echo "<br>"; echo $shipto_saddressx; echo "<br>"; } if ($shipto_saddress != $shipto_saddressx) { Code that should NOT be running if those two things match, and they do, but it still runs. } I have echoed both the variables on the screen, and they are exactly the same data, verbatim it outputs: 650 NW 123rd ST 650 NW 123rd ST It should not run the insert query below the if statement, but it does. Any ideas what is wrong in the above, I can't find it. Thanks, SK Link to comment https://forums.phpfreaks.com/topic/129400-solved-if-statement-not-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 21, 2008 Share Posted October 21, 2008 Use var_dump() to display the contents of the variables. You probably have some white-space as part of the data in one or the other. Link to comment https://forums.phpfreaks.com/topic/129400-solved-if-statement-not-working/#findComment-670870 Share on other sites More sharing options...
jaxdevil Posted October 21, 2008 Author Share Posted October 21, 2008 Oh thank god! I fixed it with your suggestion. Here is my fixed code: <? $shipto_address_temp = str_replace(' ', '', $shipto_saddress); $q = "SELECT * FROM shipto_database WHERE shipto_code = '0000001' LIMIT 1"; $res = mysql_query($q); while ($row = mysql_fetch_array($res)) { $shipto_saddressx = $row["shipto_saddress"]; $shipto_addressx_temp = str_replace(' ', '', $shipto_saddressx); echo $shipto_saddress; echo "<br>"; echo $shipto_saddressx; echo "<br>"; } if ($shipto_saddress_temp != $shipto_saddressx_temp) { Thanks!! Link to comment https://forums.phpfreaks.com/topic/129400-solved-if-statement-not-working/#findComment-670875 Share on other sites More sharing options...
discomatt Posted October 21, 2008 Share Posted October 21, 2008 An easier way if ( trim($shipto_saddress) != trim($shipto_saddressx) ) Link to comment https://forums.phpfreaks.com/topic/129400-solved-if-statement-not-working/#findComment-670876 Share on other sites More sharing options...
dennismonsewicz Posted October 21, 2008 Share Posted October 21, 2008 As I was typing that Discomatt beat me too it! So i Second his motion! Link to comment https://forums.phpfreaks.com/topic/129400-solved-if-statement-not-working/#findComment-670877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.