The original file established the $csv on line 50. What to do if $csv ==1 took place at line 95 and continues in lines 110-119 creates $filename for the .csv file.
Line 171 is probably related to the button as it is part of the form.
None of those are found in the file Ajeh submitted.
Wish I had a simple way to reinsert them but, there's a lot going on between old and new. My comparison software is not helping much. AND... Never will my skills match Ajeh.
Hopefully, this info can speed up a solution.