I have a simple web-survey where users can choose their answers using radio buttons. I check which buttons have been ticked using javascript. I am not setting the buttons to any default state, so it is possible not to answer for questions.
When I pass this to php and try inserting the results into columns of type integer, if all the radio buttons are ticked there are no problems. However, if there are any un-ticked buttons I get the following error message:
Query failed: ERROR: invalid input syntax for integer: "NaN"
I understand that this is due to the fact that my integer columns cannot handle a string, but I don't know what the best strategy for handling this is. Should I check on the javascript side or is there any approach in php where I should be testing that the values are not null?
I am inserting the results into my database using the following structure:
$query=pg_query_params( $connection, 'INSERT INTO tracking.postsurvey(answer1) values($1)', array($answer1) );