Monday, 28 August 2017

cannot modify header information - headers already sent by [php, mysql, csv]







im getting these errors on my website



Warning: Cannot modify header information - headers already sent by (output started at /home/****/public_html/monday/tuffturf/createrep.php:7) in /home/****/public_html/monday/tuffturf/createrep.php on line 103



Warning: Cannot modify header information - headers already sent by (output started at /home/****/public_html/monday/tuffturf/createrep.php:7) in /home/****/public_html/monday/tuffturf/createrep.php on line 104



Warning: Cannot modify header information - headers already sent by (output started at /home/****/public_html/monday/tuffturf/createrep.php:7) in /home/****/public_html/monday/tuffturf/createrep.php on line 105



Warning: Cannot modify header information - headers already sent by (output started at /home/****/public_html/monday/tuffturf/createrep.php:7) in /home/****/public_html/monday/tuffturf/createrep.php on line 106
query failed please try again



mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in



i have checked for white spaces at the php tags, i tried different things and i cant find the solution



the php starts at line 86 and ends at 134



$server = 'localhost';
$username = '*****';
$password = '*****';
mysql_connect($server, $username, $password);
mysql_select_db('***_turfdb')
or die ("unable to connect to mysql");

$reports = array(
'all' => 'SELECT * FROM quotepage',
'recent' => 'SELECT * FROM quotepage ORDER BY entered DESC LIMIT 20',
'oldest' => 'SELECT * FROM quotepage ORDER BY entered ASC LIMIT 20'
);
if (!array_key_exists($_POST['report'], $reports) || !isset($_POST))
{
die('Error generating report. please try again later.');
};
header("content-type:text/csv; charset=utf-8");
header('Content-Disposition:attachment;filename='.date('Y-m-d').'.csv');
header("pragma: no-cache");
header ("expires: 0");


/*if(isset($_POST) && !empty($_POST)) {
if(mysql_query($query)) {
echo "";
} else {
echo "";
echo mysql_error();
}
}*/

if(isset($_POST['header']))
{
$field = mysql_query('SHOW COLUMS FROM quotepage');
$label = array();
while($field = mysql_fetch_assoc($field));
{
$labels[] = $field ['Field'];
};
echo implode (',', $labels) . "\n";
}
$data = mysql_query($reports[$_POST['report']]);
while($row = mysql_fetch_assoc($data));
die ("query failed please try again");
{
echo implode(',', $row) . "\n";
}
?>


this is using a drop down box to select how many reports are to show up on a csv report



this is the first time i have tried to create a csv report so if more information is needed please ask

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...