What is meant to happen is when i press a button on my web page a csv file containing transaction data is downloaded. This all works fine but at the bottom of the csv file there is the code from the web page.
Does anyone know why this has happened??
my script is as follows;
Code: Select all
function csv()
{
db_connect();
$result = mysql_query("select * from transactions");
while($row = mysql_fetch_array($result))
{
$trans_id = $row['trans_id'];
$user_id = $row['user_id'];
$product_id = $row['product_id'];
$trans_date = $row['trans_date'];
$free_download = $row['free_download'];
$row2 = activity_query($product_id);
$title = $row2['title'];
$price = $row2['price'];
$data .= "$trans_id, $user_id, $product_id, $trans_date, $free_download\n";
}
$filename = "somefile.csv";
header ('Content-type: text/csv');
header ('Content-Disposition: attachment; filename='.$filename);
echo $data;
}