CodeWriter Posted January 26, 2009 Share Posted January 26, 2009 The code adds a space after the $selleruser2 variable for some reason. Any help on this problem would be appreciated. $productsdb=file("Database/Usersfile.txt"); foreach($productsdb as $key1=>$val1) {$products[$key1]=explode("||",$val1);} for($k1=0;$k1<sizeof($productsdb);$k1++) { $selleruser2=$_POST["selleruser"]; if ($selleruser2==$products[$k1][0]) { echo "match"; } } Link to comment https://forums.phpfreaks.com/topic/142417-if-statement-help/ Share on other sites More sharing options...
premiso Posted January 26, 2009 Share Posted January 26, 2009 Use trim. $selleruser2=trim($_POST["selleruser"]); Link to comment https://forums.phpfreaks.com/topic/142417-if-statement-help/#findComment-746178 Share on other sites More sharing options...
.josh Posted January 26, 2009 Share Posted January 26, 2009 trim should work but fyi that code is not adding the space. Link to comment https://forums.phpfreaks.com/topic/142417-if-statement-help/#findComment-746184 Share on other sites More sharing options...
CodeWriter Posted January 26, 2009 Author Share Posted January 26, 2009 Many thanks, it worked. Just curious though, what is adding the whitespace? Link to comment https://forums.phpfreaks.com/topic/142417-if-statement-help/#findComment-746202 Share on other sites More sharing options...
.josh Posted January 26, 2009 Share Posted January 26, 2009 could be you (or user or whatever) entering it into the form. could be how you coded the form, perhaps with default values or something. Who knows? We can't begin to tell you without seeing that code. Link to comment https://forums.phpfreaks.com/topic/142417-if-statement-help/#findComment-746234 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.