You can use this to check that a device id is valid.
Created validate_device_id() function
This should probably check that the device id is non-null as well. I'm assuming that the SQL query would work, but why bother doing it if it's not going to produce a result?
I'll update to check that ID is numerical.
Not sure what you mean by not produce a result. The query returns the device id given so that we know it's a valid id. So we can then use this function anywhere we used to just check device_id is bring used.
Added null check for $id
Added null check.