Hi, I have this code. It is not working properly. Anybody may know the solution?
Thank you
<?php include 'admin_homepage.php' ?>
<div id="sidebar1">
<b></b><br /></br></br><img src="MMU_logo.jpg" width="180" height="150"/><br />
<a href="admin_view_student.php" style="font-size:13px" >View Student</a><br />
<a href="admin_new_student_reg.php" style="font-size:13px">Add Student</a><br />
<a href="student_excel.php" style="font-size:13px">Get Excel File</a><br />
<a href="student_mailing_list.php" style="font-size:13px">Get Mailing List</a><br />
<a href="admin_email_all_students.php" style="font-size:13px">Send Email to All Students</a><br />
<a href="admin_edit_student_email.php">Email to student (admin) - (first phase)</a><br>
<a href="edit_student_email.php">Email to student (first phase)</a><br>
</div>
<div id="mainContent">
<table width="530" border="0px">
<tr>
<td width="530" height="10" bgcolor="#006" align="center"
style="font:Times New Roman; font-size:10px; color:#FFF; font-weight:bold" >Get Excel File</td>
</tr>
<tr bgcolor="#FFFFFF">
<td>
<div style="width:527px; height:470px; overflow:scroll ">
<form name="regform" action="stud_excel.php" method="post" enctype="multipart/form-data">
<table border="0" bgcolor="#FFFFFF">
<tr>
<td>Period of Industrial Training</td>
</tr>
<td><br>
Session <select name=year>
<option value="" selected></option>
<?php
$sql=mysql_query("select * from year");
while ($data=mysql_fetch_array($sql)){
echo "<option value={$data['year']}>{$data['year']}</option>";
}
?>
</select>
Trimester <select name=trimester>
<option value="" selected></option>
<?php
$sql1=mysql_query("select * from trimester");
while ($data=mysql_fetch_array($sql1)){
echo "<option value={$data[trimester]}>{$data[trimester]}</option>";
}
?>
</select>
</td>
<tr>
<td colspan="2"><br><input name="btnsub" type="submit" value="Submit"></td>
</tr>
<br>
<?php
if (isset($_POST["btnsub"]) && ($_POST["btnsub"] == "Submit"))
{
$year = $_POST['year'];
$trimester = $_POST['trimester'];
$sql2 = mysql_query("SELECT * FROM student_registration where year = '$year' and trimester = '$trimester' ORDER BY stu_ID");
$count = mysql_num_fields($sql2);
$header = '';
$data = '';
for ($i = 0; $i < $count; $i++) {
$header .= mysql_field_name($sql2, $i)."\t";
}
while($row = mysql_fetch_assoc($sql2)) {
$line = '';
foreach($row as $key => $value) {
if ($key === 'date_of_reg') {
$value = '"' . date('d/m/Y', $value) . '"';
} else {
$value = '"' . $value . '"';
}
if ($line === '') {
$line = $value;
} else {
$line .= "\t" . $value;
}
}
$data .= $line . "\n";
}
if ($data == "")
{
$data = "There is no record inside the table.";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=stud_excel.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $header."\n".$data;
}
?>
</table></form>
</td>
</tr>
</div>
</td>
</tr>
</table>
</div>
<div class="clearfloat"></div>
<div id="footer">
<center>Copyright © 2010</center>
</div>
</div>
</body>
</html>