Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/40303-solved-form-csv-not-working/
Share on other sites

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;
}
?>

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.

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.