In database table I have column called options. It has type of integer and it supposed to hold sum of bitwise values that comes from user input. User sends array of bitwise values like [1, 2, 4, 8] to server, then values are summed-up and saved in that column. When I need to output values — I just check like $options & 2. It all works fine, but I’m just wondering: Do I need somehow check user input before saving sum of bitwise values in the database?
Thanks in any advice!
short and simple:
one should always check user input. always.
in you case, you should check the different values before summing them up or doing anything else using them. if everything is ok (only numbers that are powers of 2), sum them up and process the result (save to database / whatever else).