fugix Posted May 6, 2011 Share Posted May 6, 2011 hey guys, i have my code set up to run substrings through a db to check for matches...even when there is a match it wont insert correctly $result = mysql_query("select * from friends where userid=$userid"); while($row = mysql_fetch_assoc($result)) { $first_name = $row['first_name']; $last_name = $row['last_name']; $strpos_1 = strpos($friend_1, ' '); $substr_1 = substr($friend_1, 0, $strpos_1); $substr_2 = substr($friend_1, $strpos_1); if($substr_1 == $first_name && $substr_2 == $last_name) { $sql = "insert into fav_friends values('', '$userid', '$friend_1', '$friend_2', '$friend_3', '$friend_4', '$friend_5', '$friend_6')"; $query = mysql_query($sql); } } and i don't receive any errors, any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/235666-problem-comparing-substrings-and-db-field-values/ Share on other sites More sharing options...
QuickOldCar Posted May 6, 2011 Share Posted May 6, 2011 why the empty '', for the mysql insert? Quote Link to comment https://forums.phpfreaks.com/topic/235666-problem-comparing-substrings-and-db-field-values/#findComment-1211279 Share on other sites More sharing options...
fugix Posted May 6, 2011 Author Share Posted May 6, 2011 for my id field, it doesnt get past the if statement, so in there is where the error is Quote Link to comment https://forums.phpfreaks.com/topic/235666-problem-comparing-substrings-and-db-field-values/#findComment-1211280 Share on other sites More sharing options...
btherl Posted May 6, 2011 Share Posted May 6, 2011 If it doesn't get past the "if", print out the values that are being compared. Quote Link to comment https://forums.phpfreaks.com/topic/235666-problem-comparing-substrings-and-db-field-values/#findComment-1211285 Share on other sites More sharing options...
fugix Posted May 6, 2011 Author Share Posted May 6, 2011 thats the thing, i have already done that and $substr is the same as $row['first_name'], and the same for the second set...thats why im so confused...they are the same but for some reason its not passing the if statement. Quote Link to comment https://forums.phpfreaks.com/topic/235666-problem-comparing-substrings-and-db-field-values/#findComment-1211291 Share on other sites More sharing options...
Pikachu2000 Posted May 6, 2011 Share Posted May 6, 2011 Did you compare by using var_dump() or just echo? If they look the same, my bet is that there's whitespace tacked on to one value or the other. Quote Link to comment https://forums.phpfreaks.com/topic/235666-problem-comparing-substrings-and-db-field-values/#findComment-1211293 Share on other sites More sharing options...
fugix Posted May 6, 2011 Author Share Posted May 6, 2011 thus far i only used echo, i will try var_dump() as well Quote Link to comment https://forums.phpfreaks.com/topic/235666-problem-comparing-substrings-and-db-field-values/#findComment-1211295 Share on other sites More sharing options...
fugix Posted May 6, 2011 Author Share Posted May 6, 2011 yeah thats what it was, had a whitespace before my lastnames....nice pikachu...thanks guys for your help Quote Link to comment https://forums.phpfreaks.com/topic/235666-problem-comparing-substrings-and-db-field-values/#findComment-1211301 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.