Results 1 to 1 of 1

Thread: force file download, update mysql, and display html in same file?

  1. #1
    Join Date
    Jul 2009
    Posts
    1

    force file download, update mysql, and display html in same file?

    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:

    PHP Code:
    <?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();
     
    ?>
    followed by the html section (content simplified):

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     
    <head>
    <title>&nbsp;</title>
    </head>
     
    <body>
     
    <p>
    thank you  
    </p>
     
    </body>
    </html>
    Any help or pointers would be great
    Last edited by Alan; 29 Jul 2009 at 01:30 PM. Reason: Fixed Code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •