View Full Version : force file download, update mysql, and display html in same file?

29 Jul 2009, 11:24 AM
I'm making a free download page where people can download an mp3 file in return for filling out a mailing list form.

The html form is contained in an iframe and when the visitor clicks the submit button I want to write the info to the mysql db, automatically force the download, and then display some more text/html in the iframe (e.g. 'thanks for visiting')

I had the mysql and the html working fine together, but when I implemented code to force the download, the new html page wouldn't load in the iframe anymore and it would just stay on the form page (the db still updated though).

Basically, I have found that either the download or the new html page will work, but not both...the mysql update always works.

the action of the html form is: action="add.php"

the contents of add.php are:

the php section:

$file = "Mercy.mp3";

if( !file_exists($file) ) die("File not found");

header("Content-Disposition: attachment; filename=\"" . basename($file) . "\"");
header("Content-Length: " . filesize($file));
header("Content-Type: audio/mpeg;");


mysql_query("INSERT INTO fan (lastName, firstName, zip, email, telephone)
VALUES ('$_POST[lastName]','$_POST[firstName]','$_POST[zip]', '$_POST[email]','$_POST[telephone]')");



followed by the html section (content simplified):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



thank you


Any help or pointers would be great