1

I have tried to export the mysql data result to excel. After click the Export button, the form will send parameter's value into doexport.php. The result was appeared in console.

enter image description here

<?php
session_start(); //Start the session
include('install_lang_japanese.php');

//connect to database
$dbc=mysqli_connect(_SRV,_ACCID,_PWD,"QPL");
if(!$dbc){
   die('Connect Error: ' . mysqli_connect_error());
}

if(isset($_POST['action'])){
   switch($_POST['action']){
      case 'senddatacar':

         $start = mysqli_real_escape_string($dbc,$_POST['startdate']);
         $end = mysqli_real_escape_string($dbc,$_POST['enddate']);

         $sqlex = "SELECT * FROM table";
         $result =mysqli_query($dbc,$sqlex) or die(_ERROR30.":".mysqli_error($dbc));

         $filename="cardata".date('ymd').".xls";

         header("Content-type: application/vnd.ms-excel; name='excel'");
         header(sprintf("Content-Disposition: attachment; filename=$filename"));
         header("Pragma: no-cache");
         header("Expires: 0");

         //Then echo table
         break;
    }
mysqli_close($dbc);
}

My problem is : i don't see any file has downloaded as excel


Response Header at console :

Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:keep-alive
Content-Disposition:attachment; filename=cardata170929.xls
Content-Length:2988
Content-Type:application/vnd.ms-excel; name='excel'
Date:Fri, 29 Sep 2017 05:02:19 GMT
Expires:0
Pragma:no-cache
Server:Apache/2.2.22 (Ubuntu)
nunu
  • 2,703
  • 9
  • 33
  • 55
  • 1
    do you want real excel? or just a csv? simply naming some file *.xls, does not magically make it a valid excel file. but unless you have specific requirements for excel, a csv is far more compatible –  Jul 22 '17 at 02:58
  • You need to see https://stackoverflow.com/questions/15699301/export-mysql-data-to-excel-in-php – Zaid Bin Khalid Jul 22 '17 at 03:01
  • @rtfm so you mean better i change it to csv file? – nunu Jul 22 '17 at 04:00
  • @ZaidBinKhalid I have following that code, but i can't see any file downloaded. – nunu Jul 22 '17 at 04:00
  • well that depends what you want, which i dont know. –  Jul 22 '17 at 04:31
  • @rtfm i have update my post. actually i could echo the mysql in `
    ` but no file downloaded.
    – nunu Sep 29 '17 at 07:41

0 Answers0