Export Excel using php its working in localhost but not working in Server?
Hi, I am new for php developing, here i enclosed my export excel some data from db using php code its working in localhost well but after deploying server its not working ? this is my php code
<?php
session_start();
if(!isset($_SESSION['branch']))
{
header("location:logout.php");
}
include('db.php');
include('excelwriter.calss.php');
// GET FROM Monthly Overall Report.php
$branch=$_REQUEST['branch'];
$atoms = explode('-',$_REQUEST['month']);
$year = $atoms[1];
$month = $atoms[0];
$totalamt="";
$totalbal="";
?>
<html><head><title>JAI SAIRAM ASSOCIATES</title>
<script language="javascript">
function download()
{
window.location='report.xls';
}
</script>
</head>
<body alink="#2046EE" link="#2046EE">
</head>
<body>
<form name="monthly_customer_reportview" method="post" enctype="multipart/form-data">
<center>
<font face="Arial, Helvetica, sans-serif" size="2">
<h1>JAI SAIRAM ASSOCIATES</h1>
<h2>Monthly Customer Report</h2>
<h4>Month: <?php echo $month; ?> - <?php echo $year; ?> Branch: <?php echo $branch; ?></h4>
</font>
</center>
<?php
/* Fetch Using Branach And Month-Year */
if(isset($_REQUEST["month"])){
?>
<table align="center" width="98%" border="1" cellspacing="0" cellpadding="1" >
<tr><b>
<th>Name</th>
<th>Mobile</th>
<th>Policy</th>
<th>Branch</th>
<th>PolicyAmount</th>
<th>MedicalAmount</th>
<th>PaidAmount</th>
<th>Balance</th>
<th>Manager</th>
<th>Sales Rep</th>
<th>Telecaller</th>
</b>
</tr>
</tr>
<?php
$excel=new ExcelWriter("report.xls");
if($excel==false)
echo $excel->error;
$myArr=array("SNO","NAME","MOBILE","POLICY","BRANCH","TOTAL AMOUNT","MEDICAL AMOUNT","AMOUNT PAID","BALANCE","TO MANAGER","SALES REP","TELECALLER");
$excel->writeLine($myArr);
$sel_cust=mysql_query("SELECT a.name,a.cust_id,a.mobile,a.policy,a.branch,a.total_amount,a.telecaller,a.manager,a.sales_rep,a.medi cal_amount,b.amount_paid,
a.balance FROM customer_history a INNER JOIN (SELECT cust_id,SUM(installamt) as amount_paid FROM
customer_installment_history WHERE MONTHNAME(paid_date)='$month' AND year(paid_date)='$year' AND branch='$branch'
GROUP BY cust_id) b on a.cust_id=b.cust_id GROUP BY a.cust_id")or die("Query failed".mysql_error()."actual".$sel_cust);
$count = mysql_num_rows($sel_cust);
if($count> 0){
if($sel_cust!=false){ $i=1;
while($sel_row = mysql_fetch_array($sel_cust)){
$totalamt+=$sel_row['amount_paid'];
$totalbal+=$sel_row['balance'];
$myArr=array($i,$sel_row['name'],$sel_row['mobile'],$sel_row['policy'],$sel_row['branch'],$sel_row['total_amount'],$sel_row['medical_amount'],$sel_row['amount_paid'],$sel_row['balance'],$sel_row['manager'],$sel_row['sales_rep'],$sel_row['telecaller']);
$excel->writeLine($myArr);
$i++;
?>
<tr>
<td align="center"><?php echo $sel_row['name']; ?></td>
<td align="center"><?php echo $sel_row['mobile']; ?></td>
<td align="center"><?php echo $sel_row['policy']; ?></td>
<td align="center"><?php echo $sel_row['branch']; ?></td>
<td align="center"><?php echo $sel_row['total_amount']; ?></td>
<td align="center"><?php echo $sel_row['medical_amount']; ?></td>
<td align="center"><?php echo $sel_row['amount_paid']; ?></td>
<td align="center"><?php echo $sel_row['balance']; ?></td>
<td align="center"><?php echo $sel_row['manager']; ?></td>
<td align="center"><?php echo $sel_row['sales_rep']; ?></td>
<td align="center"><?php echo $sel_row['telecaller']; ?></td>
</tr>
<?php
}
}else{
?>
<tr><td colspan="11" align="center">No Records Found</td></tr>
<?php
} ?><tr><td colspan="11" align="center"><b>Total CollectionAmount:<?php echo $totalamt; ?>Total Balance:<?php echo $totalbal; ?></td></b></tr>
</table>
<?php } }?><br>
<div align="right"><h3><a href="#" a onClick="javascript rint()">Print Page</a> * <a href="javascript :void(0);" onClick="download();" >Download Excel Report</a></h3>
</div>
</form>
</body>
</html>
mani can u plz provide the link on your server.
also make sure you have uploaded excelwriter.calss.php and configured mysql database properly.
also to find out errors, add error_reporting(E_ALL); just before session_start();
EXPORT EXCEL USING PHP with JQUERY
thanks for reply ZABI,
I found another way to export excel report using php with jquery. My code is..
<?php
session_start();
if(!isset($_SESSION['branch']))
{
header("location:logout.php");
}
include('db.php');
error_reporting(0);
// GET FROM Employee Report.php
$branch=$_REQUEST['branch'];
$designation=$_REQUEST['designation'];
?>
<html><head><title>JAI SAIRAM ASSOCIATES</title>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
<style type="text/css">
.myClass
{
font-family:verdana;
font-size:11px;
}
</style> </script>
</head><body alink="#2046EE" link="#2046EE">
<form name="employee_reportview" action="exporttoexcel.php" method="post" enctype="multipart/form-data" onsubmit='$("#datatodisplay").val( $("<div>").append( $("#ReportTable").eq(0).clone() ).html() )'>
<center>
<font face="Arial, Helvetica, sans-serif" size="2"><?php /*
<h1>JAI SAIRAM ASSOCIATES</h1>
<h2>Employee Report</h2>
<h4> Branch: <?php echo $branch; ?></h4>
</font> */?>
</center>
<?php
/* Fetch Using BRANCH */
if(isset($_REQUEST['branch'])){
?>
<table align="center">
<tr><td align="center"><h1>JAISAIRAM ASSOCIATES</h1></td></tr>
<tr><td align="center"><h2>Employee Report</h2></td></tr>
<tr><td align="center"><h4>Branch:<?php echo $branch;?></h4></td></tr>
<tr>
<td><input type="button" onClick="mani()" value="PDF">
<table width="98%"border="1" align="center" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF" id="ReportTable">
<tr bgcolor="#FFFFFF">
<th><font>EmployeeID</font></th>
<th><font>Name</font></th>
<th><font>Branch</font></th>
<th><font>Designation</font></th>
<th><font>Gender</font></th>
<th><font>DOB</font></th>
<th><font>DOJ</font></th>
<th><font>PersonalNo</font></th>
<th><font>OfficialNo</font></th>
<th><font>Address</font></th>
<th><font>Email</font></th>
<th><font>Referredby</font></th>
<th><font>ReferbyNo</font></th>
<th>Image</th>
</tr>
<?php
$searchSQL = "SELECT emp_id,name,gender,dob,doj,personal_mobile,official_mobile,perm_address,official_email,branch,design ation,referredby,referno,photo FROM employee WHERE branch='$_POST[branch]' AND designation='$designation'";
$select_name = mysql_query($searchSQL)or die ("Query failed: " . mysql_error() . " Actual query: " . $select_name);
$count = mysql_num_rows($select_name);
if($count> 0){
while($sel_row = mysql_fetch_array($select_name)){
// INSERT THE ARRRAY VALUE
$dob=date('d-m-Y',strtotime($sel_row['dob']));
$doj=date('d-m-Y',strtotime($sel_row['doj']));
$photo=$sel_row['photo'];
?>
<tr>
<td align="center"><?php echo $sel_row['emp_id']; ?></td>
<td align="center"><?php echo $sel_row['name']; ?></td>
<td align="center"><?php echo $sel_row['branch']; ?></td>
<td align="center"><?php echo $sel_row['designation']; ?></td>
<td align="center"><?php echo $sel_row['gender']; ?></td>
<td align="center"><?php echo date('d-m-Y',strtotime($sel_row['dob'])); ?></td>
<td align="center"><?php echo date('d-m-Y',strtotime($sel_row['doj'])); ?></td>
<td align="center"><?php echo $sel_row['personal_mobile']; ?></td>
<td align="center"><?php echo $sel_row['official_mobile']; ?></td>
<td align="center"><?php echo $sel_row['perm_address']; ?></td>
<td align="center"><?php echo $sel_row['official_email']; ?></td>
<td align="center"><?php echo $sel_row['referredby']; ?></td>
<td align="center"><?php echo $sel_row['referno']; ?></td>
<?php ?>
<td align="center"><?php echo '<img src="data:image/jpeg/jpg/bmb;base64,' . base64_encode( $photo ) . '" width="50" height="50" />'; ?></td>
</tr>
<?php }
}else {
?><tr><td height="20" colspan="20" align="center">No Records Found</td>
</tr>
<?php
}
}
?></table><br></td></tr></table>
<br>
<div align="right"><h3><a href="#" a onClick="javascript rint()"><input type="button" value="PRINT"></a> * <input type="hidden" id="datatodisplay" name="datatodisplay"><input type="submit" value="EXCEL"><input type="hidden" value="<?php echo $branch;?>" name="branch"><input type="hidden" name="desing" value="<?php echo $designation; ?>"><a href="pdfexport.php?branch=<?php echo $branch;?> &desing=<?php echo $designation; ?>" >PDF</a></div>
<?php
?>
</form></body></html>
<?php inlcude('footer.php'); ?>
thanks for reply ZABI,
I already uploaded excelwriter.calss.php and also configured mysql db properly. but its working in local not in server.. so i change my code to take clone of the table using jquery. This way give good result for me
if i put error_reporting(E_ALL); Just before seesion_start()- its show on warning in that page. thanks ZABI. Here i want export PDF with image and db data .. I want YOUR HELP.. Plz Help me...
actually that we need that warning message about error to figure it out. for exporting data to PDF there are couple of libraries; you can search on net.
thanks ZABI I will try with fpdf.
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks