niche Posted March 2, 2018 Share Posted March 2, 2018 (edited) here's my simple example: try { $sql = 'SELECT itemandsize FROM itemandsize WHERE sub_category = :sub_category' ; $stmt = $this->db->prepare($sql); } catch (PDOException $e) { echo $e->getMessage() . '<br>'; } try { $stmt->execute(array(':sub_category' => $var)); } catch (PDOException $e) { echo $e->getMessage() . '<br>'; } $var = 'coffee / tea' I'm certain that the slash is the problem, but don't know why. Do you know why? I thought treating $var in the array auto resolved all formatting issues. Obviously not. $var = 'coffee - tea' works fine EDIT: Is it just that slashes are used for escaping? Edited March 2, 2018 by niche Link to comment Share on other sites More sharing options...
Ingolme Posted March 2, 2018 Share Posted March 2, 2018 A slash should not cause any problem. Have you checked to see what the error message was when you tried a slash? Link to comment Share on other sites More sharing options...
niche Posted March 2, 2018 Author Share Posted March 2, 2018 (edited) all error reporting is on. no error message is displayed. EDIT: Just found out that client manually entered coffee / tea. Does that make a difference? Edited March 2, 2018 by niche Link to comment Share on other sites More sharing options...
Ingolme Posted March 2, 2018 Share Posted March 2, 2018 I can't help you solve the problem if I don't know even what the problem is. Here is what you said: Quote $var = 'coffee / tea' I'm certain that the slash is [the cause of] the problem, but don't know why. Do you know why? You mentioned a potential cause of the problem, but you didn't tell me what the problem actually is. I need to know at least two things about your problem: The behavior you expect from your code What your code is actually doing A problem only exists if the actual behavior does not match the expected behavior. Link to comment Share on other sites More sharing options...
niche Posted March 2, 2018 Author Share Posted March 2, 2018 (edited) Thanks for your patience. I expect 2 rows returned from the my code. I get zero rows back and no errors. I have visually verified that 2 rows exist with the 'coffee / tea' string. I have also verified that error reporting is working. Edited March 2, 2018 by niche Link to comment Share on other sites More sharing options...
justsomeguy Posted March 2, 2018 Share Posted March 2, 2018 If you run that query directly on your database, it returns the results you expect? I mean, you have at least one row where the sub_category field is set to "coffee / tea"? 1 Link to comment Share on other sites More sharing options...
niche Posted March 2, 2018 Author Share Posted March 2, 2018 (edited) Thanks for the question jsp. Things just got weirder. Yes, I can select 'Coffee / Tea' directly. Seems I can get the same results even after I change 'Coffee / Tea' to ' ' in the table (new issue)! This is a live Godaddy server. I wonder if it has some kind of a virus or malware? everything else works as expected. EDIT: Cleared cache, got same results on chrome, ff, and ipad. hmmm. Edited March 3, 2018 by niche Link to comment Share on other sites More sharing options...
Ingolme Posted March 3, 2018 Share Posted March 3, 2018 If the database has rows containing "coffee / tea" in the sub_category field and the code is exactly as you presented, then the issue has to be occurring either where the variable was set, or in the code that loops through query results. Start by verifying that $var has the data you expected it to at the moment the query runs. 1 Link to comment Share on other sites More sharing options...
niche Posted March 5, 2018 Author Share Posted March 5, 2018 (edited) Turn's out the problem was in my bootstrap. Thanks to ingolme and jsg. It was jsg's post that got me to thinking more broadly and ingolme's last post that zeroed in on the real problem. Thanks again for your patience. Edited March 5, 2018 by niche Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now