I've never liked wrapping the
mysql_real_escape_string
function around input I expect to be integer for inclusion in a mysql query. Recently I came across the
filter_var
function. Nice!
I'm currently using the code:
if (isset($idUserIN)
&& filter_var($idUserIN, FILTER_VALIDATE_INT)
&& 0 < filter_var($idUserIN, FILTER_SANITIZE_NUMBER_INT)
) {
$idUser = filter_var($idUserIN, FILTER_SANITIZE_NUMBER_INT);
$sql = 'SELECT * FROM TABLE_NAME WHERE idUser = '.$idUser;
} else {
// handle invalid data
}
Does this leave any holes open?
('> 0' chosen rather than '>= 0' as its a table auto_increment field, so 0 would not be a normal value)