I have a problem when trying to create an excel file based on the user input using the pear Excel_Writer library. Below is my code, when i runt it from a web page nothing happens, however if i edit the code to ignore the html code and define some variables and run the script from the commandline the excel file is created.
Can anyone help, am i missing something simple?
Thanks
<?
include ('include/dbconnect.inc');
if($_POST["report"]) {
//generate report
$Account_ID = $POST["Company"];
$Month = $POST["Month"];
$Year = $_POST["Year"];
//$Account_ID = '102210';
//$Month = '01';
//$Year = '2008';
$Month1 = $Month +1;
$lastdaysql = mktime(0, 0, 0, $Month1, 0, $Year);
$lastdate =strftime("%d", $lastdaysql);
//work out valid SQL dates to do query
$sql1date = "$Year-$Month-01 00:00:00";
$sql2date = "$Year-$Month-$lastdate 23:59:59";
require_once "Spreadsheet/Excel/Writer.php";
$query = "Select Reporting_Name from Customers WHERE Account_ID = '$Account_ID'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_object($result);
$Reporting_Name = $row->Reporting_Name;
$filename = "/var/www/html/usagereport1.xls";
$workbook =& new Spreadsheet_Excel_Writer($filename);
//format title
$format_title =& $workbook->addFormat();
$format_title->setBold();
$format_title->setSize('10');
$format_title->setUnderline(1);
$format_title->setFontFamily('Frutiger 55 Roman');
//format subheader
$format_sub =& $workbook->addFormat();
$format_sub->setBold();
$format_sub->setSize('10');
$format_sub->setFontFamily('Frutiger 55 Roman');
$usage_total =& $workbook->addFormat();
$usage_total->setBold();
$usage_total->setSize('10');
$usage_total->setFontFamily('Frutiger 55 Roman');
//format cells that need 2 decimal places
$decimalp2 =& $workbook->addFormat();
$decimalp2->setNumFormat('0.00');
// We need a worksheet in which to put our data
$worksheet =& $workbook->addWorksheet();
//set A4
$worksheet->setPaper(9);
$worksheet->setPrintScale (70);
//freeze title
$worksheet->freezePanes(array(3, 0, 4, 8));
$worksheet->setColumn(0,0,11);
$worksheet->setColumn(1,1,16);
$worksheet->setColumn(2,2,17);
$worksheet->setColumn(3,3,15);
$worksheet->setColumn(4,4,12);
$worksheet->setColumn(5,5,8.57);
$worksheet->setColumn(6,6,12.29);
$worksheet->setColumn(7,7,9);
// This is our title
$worksheet->write(0, 0, "$Reporting_Name $Account_ID", $format_title);
$colname = array('abc', '123', 'qwerty');
$worksheet->WriteRow(2, 0, $colname, $format_sub);
$workbook->close();
//echo "$filename";
}
else {
$query = "SELECT Account_ID,Customer_Name FROM Customers order by Customer_Name";
$result = mysql_query($query) or die(mysql_error());
echo "<table>
<tr>
<td colspan=\"2\"><form action=\"$_SERVER[PHP_SELF]\" method=\"post\"><select name=\"Company\">";
while($row = mysql_fetch_assoc($result))
{
echo "<option value=\"$row[Account_ID]\"> $row[Customer_Name]</option>";
}
echo "</select></td>
</tr>
<tr>
<td> </td>
<tr>
<td>Please select month for usage <select name=\"Month\">
<option value=\"01\">January</option>
<option value=\"02\">February</option>
<option value=\"03\">March</option>
<option value=\"04\">April</option>
<option value=\"05\">May</option>
<option value=\"06\">June</option>
<option value=\"07\">July</option>
<option value=\"08\">August</option>
<option value=\"09\">September</option>
<option value=\"10\">October</option>
<option value=\"11\">November</option>
<option value=\"12\">December</option>
</select>
</td>
<td>And the year <select name=\"Year\">
<option value=\"2007\">2007</option>
<option value=\"2008\">2008</option>
</td>
</tr>
<tr>
<td><input type=\"submit\" value=\"Generate Report\" name=\"report\"></td>
</table>";
echo"</form>";
}
?>