gin Posted February 27, 2007 Share Posted February 27, 2007 If I do the following it works as expected. The variable $foo is passed from the form correctly. <?php echo '"aaa","bbb"'; $out = "\n\"".$_POST['foo'].'"'; print $out; ?> However, in the following the variable doesn't pass at all. The CSV file comes out okay, but where the variable should be there is nothing. <?php header("Content-type: application/csv"); header("Content-disposition: attachment; filename=file.csv"); echo '"aaa","bbb"'; $out = "\n\"".$_POST['foo'].'"'; print $out; ?> Any advice much appreciated, for the sake of my remaining hair. Quote Link to comment https://forums.phpfreaks.com/topic/40303-solved-form-csv-not-working/ Share on other sites More sharing options...
spfoonnewb Posted February 27, 2007 Share Posted February 27, 2007 It seems to come through for me: <?php ob_start(); ?> <form action="" method="post"> <input type="text" name="foo"> <input type="submit"> </form> <?php if (!empty($_POST["foo"])) { header("Content-type: application/csv"); header("Content-disposition: attachment; filename=file.csv"); echo '"aaa","bbb"'; $out = "\n\"".$_POST['foo'].'"'; print $out; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/40303-solved-form-csv-not-working/#findComment-194976 Share on other sites More sharing options...
gin Posted February 27, 2007 Author Share Posted February 27, 2007 That doesn't work for me. The resultant file has the wrong filename (test.php instead of file.csv) and the contents are only the <form>...</form>, even when I placed the form in the else portion of that if statement. I'm using Apache 2, PHP 5, MySQL 5, if it's relevant. Quote Link to comment https://forums.phpfreaks.com/topic/40303-solved-form-csv-not-working/#findComment-194995 Share on other sites More sharing options...
gin Posted February 28, 2007 Author Share Posted February 28, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/40303-solved-form-csv-not-working/#findComment-195762 Share on other sites More sharing options...
kenrbnsn Posted February 28, 2007 Share Posted February 28, 2007 The following code works fine in both FF2 & MSIE7: <?php if (!empty($_POST["foo"])) { header("Content-type: application/csv"); header("Content-disposition: attachment; filename=file.csv"); echo '"aaa","bbb"'; $out = "\n" . '"'.$_POST['foo'].'"'; print $out; exit(); } ?> <form action="" method="post"> <input type="text" name="foo"> <input type="submit"> </form> Which browser are you using? Ken Quote Link to comment https://forums.phpfreaks.com/topic/40303-solved-form-csv-not-working/#findComment-195769 Share on other sites More sharing options...
gin Posted February 28, 2007 Author Share Posted February 28, 2007 I was using FF1.5. Actually I think it had nothing to do with the browser and all to do with the Free Download Manager that was downloading the file. Once I disabled it, the variables came thru fine. Thanks for all the help, guys! Quote Link to comment https://forums.phpfreaks.com/topic/40303-solved-form-csv-not-working/#findComment-195773 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.