I made a front-end form to allow the user to choose the state so they can export the files state by state.
Here is the modified code:
$conn = mysql_connect("localhost", "x", "x")
OR DIE (mysql_error());
@mysql_select_db ("ix", $conn) OR DIE (mysql_error());
//get the data from the state drop down
$State = addslashes($_POST['State']);
echo 'The state picked is: '.$State;
//export the data
$select = "SELECT * FROM Forms WHERE State='$State'";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
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)."\r\n";
}
$data = str_replace("\r","",$data);
if ($data == "") {
$data = "\r\n(0) Records Found!\n";
}
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=report.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\r\n$data";
?>
But now, if get the folowing errors:
The state picked is: PA
Warning: Cannot modify header information - headers already sent by (output started at /home/inthecla/public_html/forms/export.php:10) in /home/inthecla/public_html/forms/export.php on line 37
Warning: Cannot modify header information - headers already sent by (output started at /home/inthecla/public_html/forms/export.php:10) in /home/inthecla/public_html/forms/export.php on line 38
Warning: Cannot modify header information - headers already sent by (output started at /home/inthecla/public_html/forms/export.php:10) in /home/inthecla/public_html/forms/export.php on line 39
Warning: Cannot modify header information - headers already sent by (output started at /home/inthecla/public_html/forms/export.php:10) in /home/inthecla/public_html/forms/export.php on line 40
Then all the data displays, but does not produce a save window.
If I just do a SELECT * with no limiter, it works. But then I cant pick the state.
This will be sweeeet, once I get the query working!
Thanks,
Don