Often times I use methods like this to filter input. Using preg_match( )
as shown, or sometimes using a switch( )
that only acts if a POST/GET variable is one of a specific number of keywords.
if (preg_match("/^[0-9]+$/",$_POST['id_to_clear']))
{
db_query("UPDATE `table` SET `error`=0, `progress`=0 WHERE `id` = {$_POST['id']}");
}
Generally speaking, using a POST/GET variable directly in an SQL query is a huge red flag. But in this case it seems perfectly safe. Is there any way this could go awry? Something I'm not seeing?