The Best thing you can do here is redirect it to the second php page when the user clicks and in the second php file set the values in the database and then force the file download from php using readfile.
$file = <file_path>;
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}</file_path>