The rest of your post was answered, but I'll add the following. You should set your error_reporting level higher, so you are warned if you are referencing an unassigned variable. There is something wrong with your script if you aren't validating data.
When using script languages (like PHP) if by mistake the variable is not defined such insert is possible (let's say we have a variable $col1_value and after a long day of work we make a mistake and write it $col_value).