View Full Version : Numbers + Letters Match in WHERE clause

04-04-2009, 09:03 PM

Right now I have this as my mysql query:

SELECT * FROM rofl WHERE id='13159' LIMIT 1

This returns the correct table. My question is though if I add a letter to it like this:

SELECT * FROM rofl WHERE id='13159f' LIMIT 1

Why does it still return the row with the column id 13159? Its like it is ignoring the "f" and still returning the row as if it wasn't there.

If I take out all the numbers and just have it as "f" it says there is no row.

If I take out the "f" and replace it with a "5" or something, it also says there is no row.

Any ideas on why numbers + letters are acting this way in the WHERE clause, and how I should fix it?

Thanks in advance for any help!

04-04-2009, 09:17 PM
If your id column is numeric, the value on the right side of the = is parsed as a number, up to the first non-numeric digit. The "f" or any other non-numeric character you put there is a stop character.

If you are only expecting a number, you either need to validate that it only contains numeric digits or you need to cast it as an integer.

04-04-2009, 09:25 PM
Ok, thanks :D

I'll just have to validate it.