Tjalfe Posted September 11, 2009 Share Posted September 11, 2009 I am trying to make a small app which parses through an uploaded comma delimited text file and search a table to see what category each entry should be put in. $Description=trim($LineItem[$ItemNumber-2]); //$Description="CDN TIRE STORE #00069 NEWMARKET ON"; $SQLSTRING="SELECT Category FROM DescriptionCategory WHERE Description = '$Description'"; echo"<TD>$SQLSTRING</TD>"; $result = mysql_query($SQLSTRING)or die ( "Error connecting to get 'SELECT * FROM Transactions WHERE Category = '$Category' order by 'Date' Ascending ' "); if $Description=trim($LineItem[$ItemNumber-2]); is used, the SQL string looks 100% the same as when I use $Description="CDN TIRE STORE #00069 NEWMARKET ON"; both end up like this, when viewed in firefox SELECT Category FROM DescriptionCategory WHERE Description = 'CDN TIRE STORE #00069 NEWMARKET ON' the interesting thing is that only the hard coded line works, the one where I get the description from the exploded text file does not. What can I do?.. any suggestions? thanks in advance Tjalfe Quote Link to comment https://forums.phpfreaks.com/topic/173905-solved-php-sql-statement-with-variable-not-working-hardcoded-is-ok-why/ Share on other sites More sharing options...
fenway Posted September 11, 2009 Share Posted September 11, 2009 Well, if what you're saying is true, they're not the same... use === to test this. Quote Link to comment https://forums.phpfreaks.com/topic/173905-solved-php-sql-statement-with-variable-not-working-hardcoded-is-ok-why/#findComment-916738 Share on other sites More sharing options...
PFMaBiSmAd Posted September 11, 2009 Share Posted September 11, 2009 Are you getting a query error or simply zero matching rows? The line in the file probably contains some non-printing characters, like nulls or \r\n (which don't show in rendered HTML in a browser, but would show up in the "view source" in the browser.) What does the "view source" in your browser show? Try the following for the value you get from the file to see what the length actually is - var_dump($Description); Quote Link to comment https://forums.phpfreaks.com/topic/173905-solved-php-sql-statement-with-variable-not-working-hardcoded-is-ok-why/#findComment-916741 Share on other sites More sharing options...
Tjalfe Posted September 11, 2009 Author Share Posted September 11, 2009 well, I guess I am feeling like a dummy for not trying the == test.. and printing them both, I now see in the page source why there is a problem ... it seems that the data read from the file has more spaces in it.. <td>CDN TIRE STORE #00069 NEWMARKET ON</td><td>CDN TIRE STORE #00069 NEWMARKET ON</td> I guess I can blame firefox for removing spaces, as the hardcoded statement was pasted from firefox, and the data it was comparing with in the database was pasted the same way.. I guess I should go change the database to match the actual CSV file. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/173905-solved-php-sql-statement-with-variable-not-working-hardcoded-is-ok-why/#findComment-916752 Share on other sites More sharing options...
PFMaBiSmAd Posted September 11, 2009 Share Posted September 11, 2009 In HTML (all browsers), multiple real spaces are rendered as a single space. Quote Link to comment https://forums.phpfreaks.com/topic/173905-solved-php-sql-statement-with-variable-not-working-hardcoded-is-ok-why/#findComment-916753 Share on other sites More sharing options...
Tjalfe Posted September 11, 2009 Author Share Posted September 11, 2009 darn browsers.. well, at least it is working now. Thanks again.. Quote Link to comment https://forums.phpfreaks.com/topic/173905-solved-php-sql-statement-with-variable-not-working-hardcoded-is-ok-why/#findComment-916841 Share on other sites More sharing options...
fenway Posted September 12, 2009 Share Posted September 12, 2009 That's why always debug in textareas. Quote Link to comment https://forums.phpfreaks.com/topic/173905-solved-php-sql-statement-with-variable-not-working-hardcoded-is-ok-why/#findComment-917353 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.