I have a table on my site thats populated with a MySQL database.

I made a button that that once clicked, generates a CSV file and downloads it.

Works fine localhost, but live.... oh no, it prints/echoes all the text from the SQL query to the end of the script - useful NOT :eek:

All database details correct (as the table populates).

Heres the code btw:

<?
session_start();

// is the one accessing this page logged in or not?
if (!isset($_SESSION['xx']) || $_SESSION['xx'] !== true)
{
	// not logged in, move to login page
	header('Location: xx.php');
	exit;
}

//====================================================

// Connect database
$table="xxx";

// Get the PHP file containing the DbConnector class
require('xx/xx/xxx.php');

// Create an instance of DbConnector
$connector = new DbConnector();

$list = $connector->query("SELECT * FROM xx");	

//====================================================

$out = '';


$fields = mysql_list_fields(xx,$table);

$columns = mysql_num_fields($fields);


// Put the name of all fields to $out.
for ($i = 0; $i < $columns; $i++) 
{
	$l=mysql_field_name($fields, $i);
	$out .= '"'.$l.'",';

}
$out .="\n";

// Add all values in the table to $out.
while ($l = mysql_fetch_array($list)) 
{
	for ($i = 0; $i < $columns; $i++) 
	{
		$out .='"'.$l["$i"].'",';
	}
	$out .="\n";
}

// Open file export.csv.
$f = fopen ('xxx.csv','w');

// Put all values from $out to export.csv.
fputs($f, $out);
fclose($f);

header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="xxx.csv"');
readfile('xxx.csv');

//====================================================

header('Location: xxx.php');
exit;
?>

Is this me or their server setup?
Cheers anyone

    Write a Reply...