Click here to Skip to main content
14,971,296 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Following code is on my file named option.php

HTML
<head>
<style type="text/css">


</style>
</head>

<a href="index.php">Home</a>
<b><u><center><font size="100"></font> ******</center></u></b>
<hr />
<script type="text/javascript">
function printpage()
{
window.print();
}
</script>
<?php <br mode="hold" /?>
if(isset($select)&&$select!="")
{ 
$select=$_GET['select']; 
} 
?> 

<center><form id="form1" name="form1" method="post" action="#" target="_blank">   
Select Name of telecaller : 
<select name="select"> 
<option value="">--- Select ---</option> 
<?php <br mode="hold" /?>$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db('import2',$con) or die('could not select database') ; 
$res=mysql_query("SELECT telecaller FROM temp1 "); 
// Show records by while loop. 

while($row=mysql_fetch_assoc($res))
 { 
print("<option value=$row[telecaller]>$row[telecaller]</option>"); 
} 
print("</select>");
?>
     Select Date   :
<select name="select1"> 
<option value="">--- Select ---</option> 
<?php <br mode="hold" /?>$res2=mysql_query("SELECT date FROM temp1 GROUP BY date"); 
// Show records by while loop.
while($row=mysql_fetch_assoc($res2))
 { 
print("<option value=$row[date]>$row[date]</option>"); 
} 
print("</select>");
?>
     <input type="submit" name="submit" value="Select" /> 

</form>
<hr /> 
<p> 
$result=mysql_query("SELECT id,date,mobno,state,type,telecaller FROM temp1 WHERE (telecaller='$_POST[select]\r' AND date='$_POST[select1]') ORDER BY id ASC ") or die(mysql_error());    

echo"<div id="printable">";
//$result2 mysql_query("SELECT id,date,mobno,state,type,telecaller FROM temp1 WHERE date='$_POST[select]' OR telecaller='$_POST[select]\r' ") or die(mysql_error());    
print("");
echo"<form name='form2' target='_blank'>";
print("<table border="1" cellspacing="5" cellpadding="12">
<tr>
<th>Sr.No:</th>
<th>Date:</th>
<th>Mobile No:</th>
<th>State:</th>
<th>Type:</th>
<th>CIExe.:</th>
</tr>"); 
while($row=mysql_fetch_array($result))
{
print("<tr>");
print("<td>" . $row['id'] . "</td>");
print("<td>" . $row['date'] . "</td>");
print("<td>" . $row['mobno'] . "</td>");
print("<td>" . $row['state'] . "</td>");
print("<td>" . $row['type'] . "</td>");
print("<td>" . $row['telecaller'] . "</td>");
print("</tr>");
}
?>
<table><tr><a href="option2.php"> View data by Date </a></tr></table>
<br />	Download this report as
	<a href="export1.php">
	mce_href="export1.php">Excel</a>

<input type="button" value="Print this page"  önclick="printpage()" />


and on another file...
include 'connection.php';
function export_excel_csv()
{
$sql = "SELECT id,date,mobno,state,type,telecaller FROM temp1 WHERE date='$_POST[select]' OR telecaller='$_POST[select1]\r' ORDER BY id ASC ";
$rec = mysql_query($sql) or die (mysql_error());
$num_fields = mysql_num_fields($rec);
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=reports.xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    for($i = 0; $i < $num_fields; $i++ )
    {
        $header = mysql_field_name($rec,$i)."\t";
        print "$header";
    }
    print "\n";
    while($row = mysql_fetch_row($rec))
    {
        $line = '';
        foreach($row as $value)
        {                                          
            if((!isset($value)) || ($value == ""))
            {
                $value = "\t";
            }
            else
            {
                $value = str_replace( '"' , '""' , $value );
                $value = '"' . $value . '"' . "\t";
            }
            $line .= $value;
        }
        $data = trim( $line ) . "\n";
        print "$data";
    }
    print "\n";
    $data = str_replace("\\r" , "" , $data);

    if ($data == "")
    {
        $data = "\\n No Record Found!\n";                      
    }
}
export_excel_csv();
?>


Now I am getting the error about header file.. that information already send.but there is no such header I already used in option.php
What is wrong with my above coding...can anyone help me.
Posted
Updated 16-Jul-12 7:06am
v2

1 solution

Read this[^]
If you have output anything else, you can't send a header.

PHP noob error #3.

Peter
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900