the code for any page should be laid out in this general order -
initialization
post method form processing
get method business logic - get/produce data needed to display the page
html document
the post method form processing should -
detect if a post method form was submitted
keep all the input data in an array variable, then operate on elements in this array variable throughout the rest of the code
trim all the inputs at once. after you do item #2 on this list, you can accomplish this with one line of code
validate all the inputs, storing user/validation errors in an array using the field name as the array index
after the end of all the validation logic, if the array holding the errors is empty, use the form data
if an insert or update query can result in duplicate data, detect this in the error handling for the database query, and setup a message for the user telling them what was wrong with the data that they submitted
after the end of the form processing logic, if there are no user/validation errors, perform a redirect to the exact same url of the current page to cause a get request for the page.
to display a one-time success message, store it in a session variable, then test, display, and clear the session variable at the appropriate location in the html document.
if there are errors at item #5 or #7 on this list, the code will continue on to display the html document, redisplay the form, where you should populate the form field values/selects/checkboxes with any existing values so that the user doesn't need to keep reentering/selecting/checking data over and over.
you should get your code to fully work first with one form field, then one field of each type, before you worry about all the code needed for all the rest of the fields.
you can use the following to display what post data is being submitted to your code -
echo '<pre>'; print_r($_POST); echo '</pre>';
the posted code contains a php syntax error on line #13. to get php to display syntax errors, you must set php's error_reporting to E_ALL and display_errors to ON, in the php.ini on your development system (putting these settings into your code won't work for php syntax errors since your code never runs to change the settings.) stop and start your web server to get any changes made to the php.ini to take effect and confirm that the settings actually got changed by using a phpinfo() statement in a .php script file.
you should also validate any resulting web page at validator.w3.org to help make sure the markup is valid and you should only write markup that is necessary.