force download, update db, and display html from form?
Posted: Wed Jul 29, 2009 12:16 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:
followed by the html section (content simplified):
Any help or pointers would be great
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:
Code: Select all
<?php
$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;");
readfile($file);
mysql_connect("localhost","root","");
mysql_select_db("TCWList");
mysql_query("INSERT INTO fan (lastName, firstName, zip, email, telephone)
VALUES ('$_POST[lastName]','$_POST[firstName]','$_POST[zip]', '$_POST[email]','$_POST[telephone]')");
mysql_close();
?>
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> </title>
</head>
<body>
<p>
thank you
</p>
</body>
</html>