|
|
|
สอบถามปัญหา Parse error: syntax error, unexpected $con (T_VARIABLE) |
|
|
|
|
|
|
|
รบกวนสอบถามพอดีทำปุ่ม export ข้อมูลแล้วพบ error Parse error: syntax error, unexpected '$con' (T_VARIABLE) in C:\xampp\htdocs\Risa\excel2.php on line 44 ไม่เเน่ใจว่าต้องแก้อย่างไงครับ
HTML code:
Code (PHP)
<form method="POST" action= "excel2.php">
<button type="submit" class="btn btn-Primary" name="submit">Export </button>
</form>
PHP code:
Code (PHP)
Code (PHP)
[php]<?php
/** Error reporting */
error_reporting(E_ALL);
date_default_timezone_set('Europe/London');
/** PHPExcel */
require_once '../RsSHOP/Excel/php/PHPExcel.php';
echo date('H:i:s') . " Create new PHPExcel object\n";
$objPHPExcel = new PHPExcel();
echo date('H:i:s') . " Set properties\n";
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
->setLastModifiedBy("Maarten Balliauw")
->setTitle("Office 2007 XLSX Test Document")
->setSubject("Office 2007 XLSX Test Document")
->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
->setKeywords("office 2007 openxml php")
->setCategory("Test result file");
echo date('H:i:s') . " Add some data\n";
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'category')
->setCellValue('B1', 'size')
->setCellValue('D1', 'quantity')
->setCellValue('E1', 'price')
->setCellValue('H1', 'date')
$con = mysqli_connect("localhost", "root", "", "sales_db");
if(isset($_POST['submit'])){
$date1=$_POST["date1"];
$date1 = new DateTime($_POST["date1"]);
$day1 = $date1->format('Y-m-d H:i:s');
echo $day1;
$strSQL = "SELECT * FROM tb_sales where date ";
$objQuery = mysqli_query($con,$strSQL);
$i = 2;
while($objResult = mysqli_fetch_array($objQuery))
{
$objPHPExcel->getActiveSheet()->setCellValue('A' . $i, $objResult["category"]);
$objPHPExcel->getActiveSheet()->setCellValue('B' . $i, $objResult["size"]);
$objPHPExcel->getActiveSheet()->setCellValue('D' . $i, $objResult["quantity"]);
$objPHPExcel->getActiveSheet()->setCellValue('E' . $i, $objResult["price"]);
$objPHPExcel->getActiveSheet()->setCellValue('H' . $i, $objResult["date"]);
$i++;
}
mysqli_close($con);
// Rename sheet
//echo date('H:i:s') . " Rename sheet\n";
$objPHPExcel->getActiveSheet()->setTitle('sale');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Save Excel 2007 file
//echo date('H:i:s') . " Write to Excel2007 format\n";
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
ob_end_clean();
$strFileName = "sale.xlsx";
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename='.basename("$strFileName"));
$objWriter->save('php://output');
exit();
}
// Echo memory peak usage
//echo date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB\r\n";
// Echo done
//echo date('H:i:s') . " Done writing file.\r\n";
?>
[/php]
ขอบคุณครับ
Tag : PHP, MySQL, HTML
|
ประวัติการแก้ไข 2020-02-25 21:38:28 2020-02-25 21:39:54 2020-02-25 21:42:46
|
|
|
|
|
Date :
2020-02-25 21:01:27 |
By :
xcxczc223 |
View :
1008 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
มันบอกว่า error บรรทัด 44
แล้วสีแดงนั่นใช่บรรทัด 44 หรือ?
แปะคลุมโค้ดเป็นไหม?
https://www.thaicreate.com/php/forum/095986.html
บรรยายครบเรื่อง mysqli ลองตรวจดูด้วยตัวเอง
|
ประวัติการแก้ไข 2020-02-25 21:28:42
|
|
|
|
Date :
2020-02-25 21:26:55 |
By :
mr.v |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผิดตั้งแต่บันทัด 35 ผิดไวยกรณ์
|
|
|
|
|
Date :
2020-02-25 22:34:39 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|