Forum Moderators: coopster
<?
if($submit) {
include "dbconnect.php";
$content_file = "";
$content_file .= "PurchaseID,Date,IssuedTo,Amount,Reviewed,EnteredBy,Comments,JobID\r\n";
$sql = 'select * from po';
$statement = mysql_query($sql);
while($row = mysql_fetch_array($statement)) {
$content_file .= $row['PurchaseID'] . ',' . $row['Date'] . ',' . $row['IssuedTo'] . ',' . $row['Amount'] . ',' . $row['Reviewed'] . ',' . $row['EnteredBy'] . ',' . $row['Comments'] . ',' . $row['JobID'] . "\r\n";
}
$output_file = 'purchaseorders.csv';
@ini_set('zlib.output_compression', 'Off');
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding: none');
//This should work for IE & Opera
header('Content-Type: application/octetstream; name="' . $output_file . '"');
//This should work for the rest
header('Content-Type: application/octet-stream; name="' . $output_file . '"');
header('Content-Disposition: inline; filename="' . $output_file . '"');
echo $content_file;
exit();
}
?>
<form name="form1" method="post" action="downloadpo.php">
<input type="submit" name="submit" value="Download">
</form>
My only problem is that when I save the csv I only get the field names from the database. It is very nice to get those, but the records would be a definite bonus.
I am so grateful for the help I have found here. Can anyone possibly see what I have done wrong?
Thanks so much for your help.