I'm trying to download some query results to an excel file using the following code. Can anyone tell me why I'm getting an error?
<?
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename=contacts.xls" );
header( "Content-Description: Excel output" );
include("includes/dbconn.php");
?>
<?
$sql = "SELECT * FROM contacts";
$result = @($sql, $dbconn);
if (!$result) {
echo( "<P>Unable to execute query at this time.</P>" );
exit();
}
while ($row = mysql_fetch_array($result)) {
$name = $row['name'];
$email = $row['email'];
$phone = $row['phone'];
$dt = $row['dt'];
$company = $row['company'];
echo ("<tr>");
echo ("<td width=\"20%\" align=\"left\" bgcolor=#919AB5><font face=\"verdana\" size=\"1\" color=\"white\"><b>$dt</b></font></td>");
echo ("<td width=\"20%\" align=\"left\" bgcolor=#919AB5><font face=\"verdana\" size=\"1\" color=\"white\">$name</font></td>");
echo ("<td width=\"20%\" align=\"left\" bgcolor=#919AB5><font face=\"verdana\" size=\"1\" color=\"white\">$email</font></td>");
echo ("<td width=\"20%\" align=\"left\" bgcolor=#919AB5><font face=\"verdana\" size=\"1\" color=\"white\">$phone</font></td>");
echo ("<td width=\"20%\" align=\"left\" bgcolor=#919AB5><font face=\"verdana\" size=\"1\" color=\"white\">$company</font></td>");
echo ("</tr>");
}
?>
😕