Jump to content

why it show those HTML code out ?


angel777

Recommended Posts

Hi .. i have problem in exporting data to excel..

the data exported into excel is correct... but .. it includes other unnessary things as below.

 

below is whatever that is printed into the excel sheet.. why it includes those html code ?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 


<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
<LINK href="oscc.css" type=text/css rel=stylesheet> 

</head> 

<body> 
<table width="100%"> 
<tr> 
<TD class=tdNB align=center ><B>Welcome: </B></TD> 
</tr></table> 



<TABLE 
style="BORDER-RIGHT: 1px dashed; BORDER-TOP: 1px dashed; BORDER-LEFT: 1px dashed; COLOR: #666633; BORDER-BOTTOM: 1px dashed" 
cellSpacing=1 cellPadding=2 width=600 align="center" border=0> 
<TBODY> 
<TR> 
<TD class=colspan align=middle colSpan=2>Explaination</TD> 
</TR> 
<TR> 
<TD vAlign=center><B>1.</B> Kata Laluan Asal: Masukkan kata laluan anda 
yang asal. Pastikan kata laluan anda adalah betul.<BR><B>2.</B> Kata 
Laluan Baru: Masukkan kata laluan yang baru paling kurang 6 
aksara.<BR><B>3.</B> Pengesahan Kata Laluan: Sahkan kata laluan anda yang 
baru pastikan pengesahan sama dengan kata laluan yang baru.<BR><B>4.</B> 
Kata laluan tidak boleh kosong atau mengandungi sebarang ruang 
kosong.<BR></TD></TR></TBODY></TABLE> 
" " 
" <form action=""successful_login.php"" method=""post"">" 
" " 
" <INPUT class=button type=submit value=Export name=submit>" 
" " 
" </form>" 
" " 
</body> 
</html> 
Username Address Address2 Postcode State Telephone Fax No Mobile No Email Panel Name Doc in Charge Admin Contact Operating Hours X-Ray-Facilities Other Facility HQ Branch Specialist Tag Date Accepted Pay To Bank Name Bank Account No Direct Bank In
lyealain77 lintang payat teruong batu lancang 11060 PulauPinang 8274258 9999 88888 hehe heheeeehh 9999990 123 Y fasdfasfasf N Y d 0000-00-00 00:00:00  maybank 123123123 N
1 1 1 1 Kedah 1 1 1 1 1 1 1 1 d 0000-00-00 00:00:00 
ling vcc vcc 123 PulauPinang 123 123 123 123 123 123 123 123 Y Y d 0000-00-00 00:00:00 Y
geneivieve 1 1 1 Kedah 1 1 1 [email protected] 1 1 1 1 1 3/30/2008  

 

 

 

my full code as below

 

<?php ob_start(); 
session_start(); 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
<LINK href="oscc.css" type=text/css rel=stylesheet> 

</head> 

<body> 
<table width="100%"> 
    <tr> 
  <TD class=tdNB align=center ><B>Welcome:  <?php  echo $_SESSION[username] ?></B></TD> 
</tr></table> 
  
  

<TABLE  
style="BORDER-RIGHT: 1px dashed; BORDER-TOP: 1px dashed; BORDER-LEFT: 1px dashed; COLOR: #666633; BORDER-BOTTOM: 1px dashed"  
cellSpacing=1 cellPadding=2 width=600 align="center" border=0> 
  <TBODY> 
  <TR> 
    <TD class=colspan align=middle colSpan=2>Explaination</TD> 
  </TR> 
  <TR> 
    <TD vAlign=center><B>1.</B> Kata Laluan Asal: Masukkan kata laluan anda  
      yang asal. Pastikan kata laluan anda adalah betul.<BR><B>2.</B> Kata  
      Laluan Baru: Masukkan kata laluan yang baru, paling kurang 6  
      aksara.<BR><B>3.</B> Pengesahan Kata Laluan: Sahkan kata laluan anda yang  
      baru, pastikan pengesahan sama dengan kata laluan yang baru.<BR><B>4.</B>  
      Kata laluan tidak boleh kosong atau mengandungi sebarang ruang  
    kosong.<BR></TD></TR></TBODY></TABLE> 
     
    <form action="successful_login.php" method="post"> 
     
        <INPUT class=button type=submit value=Export name=submit> 
     
    </form> 
     
</body> 
</html> 
<?php 
//Written by Dan Zarrella. Some additional tweaks provided by JP Honeywell 
//pear excel package has support for fonts and formulas etc.. more complicated 
//this is good for quick table dumps (deliverables) 


if(isset($_POST[submit])) 
{     
     
    include('./uservar.php'); 
    $connection=mysql_connect($server, $user, $pass); 
        if(!$connection)                     
            die("Connection failed");         
                         
        else 
        { 
            mysql_select_db($db);     
             
             
             
             //Create file and populate header row  
                $myFile = "export.csv";  
                $fh = fopen($myFile, 'w') or die("can't open file");  
                $headerData = "Username,Address,Address2,Postcode,State, Telephone, Fax No, Mobile No, Email, Panel Name, Doc in Charge, Admin Contact, Operating Hours, X-Ray-Facilities, Other Facility, HQ, Branch, Specialist Tag, Date Accepted, Pay To , Bank Name, Bank Account No, Direct Bank In\r\n";  
                fwrite($fh, $headerData);  
                fclose($fh);  
                 
                //Query record  
                $sql="select * from panel_registration";  
                $result=mysql_query($sql);  
                while ($record = mysql_fetch_array($result)) // while #1  
                {  
                          
                  //Assign values to variables  
                  $_username=$record['username'];  
                  $_Addresss_1=$record['Addresss_1'];  
                  $_Addresss_2=$record['Addresss_2'];  
                  $_Post_Code=$record['Post_Code'];  
                  $_State_ID=$record['State_ID'];  
                  $_Telephone_No=$record['Telephone_No'];  
                  $_Fax_No=$record['Fax_No'];  
                  $_Mobile_No=$record['Mobile_No'];              
                  $_Email_Address=$record['Email_Address'];  
                  $_Panel_Name=$record['Panel_Name'];  
                  $_Doc_in_Charge=$record['Doc_in_Charge'];  
                  $_Admin_Contact=$record['Admin_Contact'];  
                  $_Operating_Hours=$record['Operating_Hours'];  
                  $_XRay_Facility=$record['XRay_Facility'];  
                  $_Other_Facility=$record['Other_Facility'];  
                  $_HQ=$record['HQ'];  
                  $_Branch=$record['Branch'];                   
                  $_Date_Accept=$record['Date_Accept'];  
                  $_Specialist_Tag=$record['Specialist_Tag'];  
                  $_PayTo=$record['PayTo'];  
                  $_Bank_Name=$record['Bank_Name'];  
                  $_Bank_Acct_No=$record['Bank_Acct_No'];  
                  $_Direct_Bank_In=$record['Direct_Bank_In'];  
                  
                    
                 
                  //Write record to file  
                  $myFile = "Data_export.csv";  
                  $fh = fopen($myFile, 'a') or die("can't open file");                                                                                                                                                                                                                                                                                                                                                                                                                                     
                  $stringData = $_username.",".$_Addresss_1.",".$_Addresss_2 .",".$_Post_Code.",".$_State_ID.",".  $_Telephone_No.",". $_Fax_No.",". $_Mobile_No.",". $_Email_Address.",".$_Panel_Name.",". $_Doc_in_Charge.",". $_Admin_Contact.",".$_Operating_Hours .",". $_XRay_Facility .",". $_Other_Facility .",". $_HQ .",". $_Branch .",". $_Specialist_Tag .",".$_Date_Accept .",".  $_PayTo .",". $_Bank_Name .",". $_Bank_Acct_No  .",". $_Direct_Bank_In ;  
                   
                  fwrite($fh, $stringData);  
                  fclose($fh);  
                 
                $data .= trim($stringData)."\r\n";  
                 
                } // end while #1 statement  
                 
                $data = rtrim($data);  
                 
                //Save file  
                header("Content-type: application/x-msdownload");   
                header("Content-Disposition: attachment; filename=$myFile");   
                header("Pragma: no-cache");   
                header("Expires: 0");   
                print "$headerData$data";  
                 
                //Delete file from server  
                unlink($myFile);  

         
     
    } 
    } 
    ob_flush(); 
?> 

Link to comment
https://forums.phpfreaks.com/topic/99416-why-it-show-those-html-code-out/
Share on other sites

this is pointless to rename just use the array right of mysql

<?php
                  //Assign values to variables  
                  $_username=$record['username'];  
                  $_Addresss_1=$record['Addresss_1'];  
                  $_Addresss_2=$record['Addresss_2'];  
                  $_Post_Code=$record['Post_Code'];  
                  $_State_ID=$record['State_ID'];  
                  $_Telephone_No=$record['Telephone_No'];  
                  $_Fax_No=$record['Fax_No'];  
                  $_Mobile_No=$record['Mobile_No'];              
                  $_Email_Address=$record['Email_Address'];  
                  $_Panel_Name=$record['Panel_Name'];  
                  $_Doc_in_Charge=$record['Doc_in_Charge'];  
                  $_Admin_Contact=$record['Admin_Contact'];  
                  $_Operating_Hours=$record['Operating_Hours'];  
                  $_XRay_Facility=$record['XRay_Facility'];  
                  $_Other_Facility=$record['Other_Facility'];  
                  $_HQ=$record['HQ'];  
                  $_Branch=$record['Branch'];                   
                  $_Date_Accept=$record['Date_Accept'];  
                  $_Specialist_Tag=$record['Specialist_Tag'];  
                  $_PayTo=$record['PayTo'];  
                  $_Bank_Name=$record['Bank_Name'];  
                  $_Bank_Acct_No=$record['Bank_Acct_No'];  
                  $_Direct_Bank_In=$record['Direct_Bank_In'];  
?>

 

also if any fields have html that html will carry into the excel file.  so check the vars you are using fwrite on to verify they are html fee

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.