1

This is error appears when I try to open the exported file, when I click yes the file opens but has error above the table:

enter image description here

<?php require '../backend/dbcon.php'; 
$query=mysql_query( "SELECT * FROM membership");
$total=mysql_num_rows($query);
if ($total>0) { $output .= '
<table border="1">
  <tr>
    
    <th>NO</th>
    <th>Names</th>
    <th>Email</th>
    <th>Phone</th>
    <th>Amount(N$)</th>
    <th>Payment</th>
  </tr>'; while ($row = mysql_fetch_array($query)) { $output .= '
  <tr>
    <td>' . $row["id"] . '</td>
    <td>' . $row["names"] . '</td>
    <td>' . $row["personal_email"] . '</td>
    <td>' . $row["personal_phone"] . '</td>
    <td>' . 110 . '</td>
    <td>' . $row["payment"] . '</td>
  </tr>
  '; } $output .= '
</table>'; 
header("Content-Type: application/xls"); 
header("Content-Disposition: attachment; filename=Membe.xls"); echo $output; }
Shadow
  • 33,525
  • 10
  • 51
  • 64
Ananias
  • 21
  • 4
  • When it says your file is corrupt or can't open for some reason, you most likely have errors or warnings being echo on the screen, which will ruin your excel file... – Naruto Apr 22 '16 at 08:12
  • 2
    That's because you're creating a file containing html markup, and trying to tell Excel that it's a BIFF-format xls file..... html !== Excel.... you'll get that message unless you actually create a real BIFF-format Excel file – Mark Baker Apr 22 '16 at 08:12
  • what do you suggest I must do? @MarkBaker – Ananias Apr 22 '16 at 08:17
  • 2
    The choice is yours, whether to live with that message or not; but there are a good many library options that would allow you to create a real native-format Excel files, including my own PHPExcel – Mark Baker Apr 22 '16 at 08:27
  • 1
    The `mysql_*` functions in PHP are deprecated and shouldn't be used. Please read [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) for information on why and what to replace them with. – Matt Raines Apr 22 '16 at 08:31
  • use some in built php library to create excel....like : https://phpexcel.codeplex.com/ http://search.cpan.org/dist/Spreadsheet-WriteExcel/lib/Spreadsheet/WriteExcel.pm#EXAMPLES – Dipanwita Kundu Apr 22 '16 at 09:48

0 Answers0