Weird issue: alphabetical values ignored in queries - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Weird issue: alphabetical values ignored in queries (/showthread.php?tid=43578) |
Weird issue: alphabetical values ignored in queries - El Forum - 07-16-2011 [eluser]cyberjunkie[/eluser] I'm tremendously baffled and annoyed by this. I'm passing a third URL segment that is a user id. e.g. Quote:http://mysite.com/index.php/profile/user/63 The 3rd segment is captured by my function: Code: function user($user_id) So the function above returns data for user 63. If I type a user id that does not exists, e.g. 6347267, it redirects home. However if I add letters to a valid user id, e.g. 63ghjfs it somehow gets the right data. It seems to somehow ignore the letters. The query looks like this: Code: SELECT * FROM (`users`) WHERE `user_id` = '62ghjfs' LIMIT 1 User ids are strictly integers. How in the world is it returning the right data when id "62ghjfs" does not exist! This is so confusing.. Weird issue: alphabetical values ignored in queries - El Forum - 07-16-2011 [eluser]Eric Barnes[/eluser] My first advice is to cast $user_id to an int so that you are 100% positive you are in fact with the expected data type. Code: $user_id = (int) $user_id; Weird issue: alphabetical values ignored in queries - El Forum - 07-18-2011 [eluser]cyberjunkie[/eluser] Thanks for the advice Eric! I will definitely do that. |