I have written the below code to generate a report in excel but it is only showing the headers on webpage,not even generating excel file.please help me in this regards.
<?php
error_reporting(0);
include("database.php");
$fromdate= $_GET['fromdate'];
$todate = $_GET['todate'];
echo $fromdate;
$out = '';
$csv_hdr .= "\n\n\n Id,Date,Time,Movie,Name,Email,Phone,Approved";
$out .= $csv_hdr;
$out .= "\n\n";
$result1 = mysql_query("SELECT * from bookings where (date)date between '$fromdate' and '$todate'");
while($row = mysql_fetch_array($result1))
{
$id= $row["id"];
$date= $row["date"];
$time= $row["time"];
$movie= $row["movie"];
$name= $row["name"];
$email= $row["email"];
$phone= $row["phone"];
$approved= $row["approved"];
}
$csv_output .= $id .", ".$date.", ".$time.", ".$movie.", ".$name.", ".$email.", ".$phone.", ".$approved;
$csv_output .= "\n";
$out .= $csv_output ."\n\n";
$filename = "FirstLook-$fromdate-$todate";
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: attachment; filename=".$filename.".csv");
echo "\n "." Report of FirstLook Preview";
print $out;
exit;
?>
NEW UPDATE:when is commented error_reporting(0); I get these errors:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/public_html/mysite.com/admin/loggedin/bet_date_excel.php on line 18
Warning: Cannot modify header information - headers already sent by (output started at /home/vrwebqbj/public_html/mysite.com/admin/loggedin/bet_date_excel.php:8) in /home/public_html/mysite.com/admin/loggedin/bet_date_excel.php on line 37
Warning: Cannot modify header information - headers already sent by (output started at /home/public_html/mysite.com/admin/loggedin/bet_date_excel.php:8) in /home/public_html/mysite.com/admin/loggedin/bet_date_excel.php on line 39
Report of FirstLook Preview Id,Date,Time,Movie,Name,Email,Phone,Approved , , , , , , ,