Code: Select all
<title>ODCMM - Conway ODC</title>
<style type="text/css" media="screen">
ul li{
list-style-type:none;
}
</style>
<fieldset><center><h2><strong>Monthly Report</strong></h2></center></fieldset>
<Center><br><br><br><br><br><br><br><br><br><br><br><br><br>
<p>You must search using the month and year (ie. Month: 8 Year: 2010)</p>
<form method="post" action="monthlyreport.php?go" id="searchform">
Month:<input type="text" name="month"> Year:<input type"text" name="year">
<input type="submit" name="submit" value="Search">
</form></center>
<?php
// Edit the $Host, $User $Password, $DBName and $TableName vars only! //
$Host = "**************";
$User = "*****";
$Password = "******";
$DBName = "metrics";
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z0-9]+/", $_POST['month'])){
$month=$_POST['month'];
$year=$_POST['year'];
$link = mysql_connect ($Host, $User, $Password) or die('Could not connect: ' . mysql_error());
mysql_select_db($DBName) or die('Could not select database' . mysql_error());
$select = "SELECT id, datemonth, dateday, dateyear, userid, shift, rotname, rotationcomplete, totaltapesreq, totalentered, totalremoved, comments FROM shiftmetrics WHERE datemonth LIKE '%" . $month . "%' AND dateyear LIKE '%" . $year . "%'";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$csv_output .= mysql_field_name($export, $i) . "\t"; //the error occurs here
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=database_dump.xls");
header("Pragma: no-cache");
header("Expires: 0");
print $csv_output."\n".$data;
exit;
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Download MySQL Table Code</title>
</head>
<body>
</body>
</html>

