我正在尝试将搜索数据导出到Excel中但我收到错误NetworkError: 500 Internal Server Error - http://
任何人都可以告诉我如何修复此错误?
以下是我的代码。
任何人都可以告诉我如何解决这个错误,我哪里出错了?
它没有导出它会打开cmsexp_to_excel.php,这在firebug中是空白的,显示错误。
Filterdata.php
<?php
$mediaexport=$_GET["media"];
?>
<form action = "cmsexp_to_excel.php" method = "post">
<input checked type='checkbox' name="media" value="<?php echo $mediaexport;?>" style='visibility:hidden' >
<input type="image" value="" src="/img/export.png" class="export" style='margin:0 5px -9px 183px;cursor:pointer;'>
</form>
cmsexp_to_excel.php
<?php
require_once 'Classes/PHPExcel.php';
$mediaexport=$_GET['media'];
$date = date('d.m.Y', time());
$sql = "SELECT DISTINCT contact.`id` , contact.`contactgroup` , contact.`media` , contact.`media2` , contact.`email1` , contact.`nationality` , contact.`country3` , contact.`twon` , contact.`area` , contact.`gender` , contact.`married` , contact.`children` , contact.`driverslicense`
FROM contact";
if ($media !="" && $media !="Empty" && $media == "sms" ){
$sql.=" and media = '".$media."'";
}
if ($media !="" && $media !="Empty" && $media == "email" ){
$sql.=" and media2 = '".$media."'";
}
if ($media !="" && $media !="Empty" && $media == "sms,email" ){
$sql.=" and media = 'sms' and media2 = 'email' ";
}
$queryRes = mysql_query($sql);
// start creating excel
$objPHPExcel = new PHPExcel();
$objPHPExcel->setActiveSheetIndex(0);
$sheet = $objPHPExcel->getActiveSheet();
// your data
$sheet->setCellValueByColumnAndRow(0,1,'Contact group');
$sheet->setCellValueByColumnAndRow(1,1,'Media');
$sheet->setCellValueByColumnAndRow(2,1,'E-mail');
$sheet->setCellValueByColumnAndRow(3,1,'Nationality');
$sheet->setCellValueByColumnAndRow(4,1,'Country');
$sheet->setCellValueByColumnAndRow(5,1,'City');
$sheet->setCellValueByColumnAndRow(6,1,'Area');
$sheet->setCellValueByColumnAndRow(7,1,'Gender');
$sheet->setCellValueByColumnAndRow(8,1,'Married');
$sheet->setCellValueByColumnAndRow(9,1,'Children');
$sheet->setCellValueByColumnAndRow(10,1,'Drivers license');
// start list
$offset = 2;
$total_cost = 0;
$total_sms = 0;
while( $row = mysql_fetch_assoc($queryRes)){
$sheet->setCellValueByColumnAndRow(0,$offset,$row['contactgroup']);
$sheet->setCellValueByColumnAndRow(1,$offset,$row['media']);
$sheet->setCellValueByColumnAndRow(2,$offset,$row['email1']);
$sheet->setCellValueByColumnAndRow(3,$offset,$row['nationality']);
$sheet->setCellValueByColumnAndRow(4,$offset,$row['country1']);
$sheet->setCellValueByColumnAndRow(5,$offset,$row['twon']);
$sheet->setCellValueByColumnAndRow(6,$offset,$row['area']);
$sheet->setCellValueByColumnAndRow(7,$offset,$row['gender']);
$sheet->setCellValueByColumnAndRow(8,$offset,$row['married']);
$sheet->setCellValueByColumnAndRow(9,$offset,$row['children']);
$sheet->setCellValueByColumnAndRow(10,$offset,$row['driverslicense']);
$offset++;
}
$attachment_name= "Export-DB$date";
//OUTPUT
header("Content-Type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=$attachment_name.xls");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit();
?>
答案 0 :(得分:1)
$sheet->setCellValueByColumnAndRow(4,$offset,$row['country1']);
应该是
$sheet->setCellValueByColumnAndRow(4,$offset,$row['country3']);