mercredi 29 janvier 2020

Exporting mysql datababse to Excel

now am trying to export mysql database to excel sheet and i am using php/mysql to preform that and everytime i get this error i've tried everything but i can't find a solutions for this case

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in staff/export.php on line 9

and here's the export.php

<?php  
//export.php  
$connect = mysqli_connect("localhost", "user", "password, "dbname");
$output = '';
if(isset($_POST["export"]))
{
 $query = "SELECT * FROM tbl_customer";
 $result = mysqli_query($connect, $query);
 if(mysqli_num_rows($result) > 0)
 {
  $output .= '
   <table class="table" bordered="1">  
<tr><th>Id</th><th>Customer name</th><th>Agent name</th><th>Phone Number</th><th>Email</th><th>Brand Name</th><th>Field</th><th>Website</th><th>comments</th></tr>
  ';
  while($row = mysqli_fetch_array($result))
  {
   $output .= '
    <tr>  
                         <td>'.$row["Id"].'</td>  
                         <td>'.$row["Customer name<"].'</td>  
                         <td>'.$row["Agent name"].'</td>  
       <td>'.$row["Phone Number"].'</td>  
       <td>'.$row["Email"].'</td>
              <td>'.$row["Brand Namel"].'</td>
        <td>'.$row["Field"].'</td>
        <td>'.$row["Website"].'</td>
         <td>'.$row["comments"].'</td>
                    </tr>
   ';
  }
  $output .= '</table>';
  header('Content-Type: application/xls');
  header('Content-Disposition: attachment; filename=download.xls');
  echo $output;
 }
}
?>



Aucun commentaire:

Enregistrer un commentaire