Everytime I think that I am home free I run into another problem. I have the following code to save a table from my database to an excel/csv file. This worked fine for a while but then all of a sudden it has stopped. I am not sure what change that I made recently has made it not work.
[code=php]
<?php
// start session
session_start();
if (!$_SESSION[‘auth’] >= 1) {
// check if authentication was performed
// else die with error
die (“ERROR: Unauthorized access!”);
}
else
{
// Outputting a CSV
header(‘Content-type: text/csv’);
header(‘Content-Disposition: attachment; filename=”goodlink_data.csv”‘);
// Main
$connection = mysql_connect(‘localhost’, ‘CapitalC’, ‘waterloo’) or die (“Connection could not be made.”);
mysql_select_db(‘goodlink’) or die (“Could not connect to database.”);
$query = “SELECT * FROM `license_data` “;
if ($_SESSION[‘user’] != “”)
{
$query .= ” WHERE `entry_date` = ‘”.$_SESSION[‘date’].”‘”;
}
if ($_SESSION[‘user’] != “all” && $_SESSION[‘user’] != “”)
{
$query .= ” and `entered_by` = ‘”.$_SESSION[‘user’].”‘”;
}
$result = mysql_query ($query) or die (“Error in query: $query. “.mysql_error());
echo “Subscriber ID,Company/Customer Name,Customer Address Line 1,Customer Address Line 2,Customer City,Customer Province,Customer Postal Code,User Name,Product Identifier,End Customer Extended Price,Customer Billing Account Number,Mobile Number,ESN,Date,Bill Cycle Date,Market,Entry Date,Entry Time,Entered By,Record IDn”;
while($row = mysql_fetch_row($result))
{
foreach ($row as $value)
{
echo “$value,”;
}
echo “n”;
}
}
?>
My excel error is attached below:
[upl-file uuid=d73e42a2-8711-4ab3-b1d4-ba49ca775fd1 size=23kB]excel_error.JPG