Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Numbers + Letters Match in WHERE clause

    Hey,

    Right now I have this as my mysql query:

    Code:
    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:

    Code:
    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!

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,024
    Thanks
    2
    Thanked 314 Times in 306 Posts
    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.
    Last edited by CFMaBiSmAd; 04-04-2009 at 08:33 PM. Reason: fixed case -> cast
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, thanks

    I'll just have to validate it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •