0

This error first occurred in a php function, but after a while of troubleshooting I am getting same results in phpmyadmin.

I have a simple SQL statement SELECT * FROM tbl_movie WHERE title= "movie"

And I get nothing returned, I am copying and pasting (also tried typing it in) from the table. So there should be a match. Tried this with a many values that should work, same result (0 rows returned).

Oddly enough SELECT * FROM tbl_movie WHERE title LIKE "%movie%". Returned the desired row.

What is going on here?

Edit: I have tried everything I can think of to weed out the possibility of spaces messing it up. Sae results with: spaces on each/both sides, items with/without spaces.

2
  • 2
    Can you show the row? Any white space around it or other chars? Commented Nov 9, 2013 at 2:27
  • perhaps you have a space or some other character in the row you are searching for? Commented Nov 9, 2013 at 2:28

2 Answers 2

3

You should try single quotes rather than double quotes.

If you get the same results, there is probably white space either before or after the word 'movie' in that column. Try this to figure that out. IF the length is something other than 5, that's your explanation.

 SELECT LENGTH(title), HEX(title), title
   FROM tbl_movie
  WHERE title like '%movie%'
Sign up to request clarification or add additional context in comments.

4 Comments

So I tried that and it returned 6 as the length instead of 5. But I tried the query with spaces on each side.
This means there is some undisplayable character either before or after the word 'movie'. That character doesn't have to be a space.
Try SELECT HEX(title), title . You'll get a hex dump of the character in the title. This might help you figure out the rubbish character.
AHA, there is '0D' at the end of the hex values for these strings.
0

Please test this code:

SELECT * FROM `tbl_movie` WHERE `title` LIKE '%"movie"%'

See the "" and change for ' or `.

Sometimes the single and double quotes are problems when performing searches in mysql.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.