internet explorer error-while saving data in excel

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pradeepcarya
Forum Newbie
Posts: 5
Joined: Tue Nov 08, 2011 4:36 am

internet explorer error-while saving data in excel

Post by pradeepcarya »

hi,

I am generating excel as per below code.

Code: Select all

<?PHP 

$Driver_Name=$_POST[`Driver_Name`];

$now_date=date('d-m-Y');

$fp = fopen('CTT_Driver_Dump.xls', "w");

$header ="
<table align='center' bgcolor='#666666' width='1000px' > 
<tr bgcolor='green'>
<td colspan=2>Date : $now_date</td>
<td colspan=16 align='center'><font size=+3><strong> CTT Driver Dump</strong></font> </td>
</tr>

<tr bgcolor='#808080'>
<th>Status</th>
<th>Driver Name</th>
<th>Driver DL NO</th>
<th>Driver Mobile</th>
<th>Driver Address</th>
<th>CAB Number</th>
<th>CAB Type</th>
<th>CAB Capcity</th>
<th>Vendor Id</th>
<th>Route No</th> 
<th>Start Date</th>
<th>End Date</th>
<th>Total CAB Route</th>
<th>Remarks</th> 
</tr> ";

fwrite($fp, $header); 

$sql = "select `Driver_Name`, `Driver_DL_NO`, `Driver_Mobile_No`, `Driver_Address`,`Cab_Number`, 
`Cab_Type`, `Cab_Status`, `Tot_Cab_route`, `Cab_Capcity`,DATE_FORMAT(`Cab_Strt_Dt`,'%d-%m-%Y')Cab_Strt_Dt, 
DATE_FORMAT(`Cab_End_Dt`,'%d-%m-%Y') `Cab_End_Dt`, `Route_Dtl`, `Vendor_Id`, `Vendor_Name`, `Vendor_Mobile`,`Vendor_Address`, 
`Remarks`, `Created_By`, `Created_On`, `Updated_By`, 
`Updated_On`,`Timestmp`
from ctt_cab_detail 
where Driver_Name = ‘$ Driver_Name’ 
order by Driver_Name asc,Timestmp desc ";

$result = mysql_query($sql);





while($row = mysql_fetch_array($result)) 
{ 
$data=" 
<tr bgcolor='#9C9C4E' > 
<td>$row[Cab_Status]</td>
<td>$row[Driver_Name]</td>
<td>$row[Driver_DL_NO]</td>
<td>$row[Driver_Mobile_No]</td>
<td>$row[Driver_Address]</td>
<td>$row[Cab_Number]</td>
<td>$row[Cab_Type]</td>
<td>$row[Cab_Capcity]</td>
<td>$row[Vendor_Id]</td>
<td>$row[Route_Dtl]</td>
<td>$row[Cab_Strt_Dt]</td>
<td>$row[Cab_End_Dt]</td>
<td>$row[Tot_Cab_route]</td> 
<td>$row[Remarks]</td>
</tr> ";

fwrite($fp, $data); 
} 

fclose($fp); 
}
I am using google chrome as internet explorer and I am getting accurate result(excel for driver name given in html form).

But when i am using internet explorer, i am getting always previous excel.
I need to use internet explorer on client pc.

Kindly tell me how to fix issue in case of internet explorer.


rgds,
pc
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: internet explorer error-while saving data in excel

Post by mikosiko »

most likely because you have errors in your code... I see errors in these lines:

Code: Select all

$Driver_Name=$_POST[`Driver_Name`];  // Incorrect usage of backtics

where Driver_Name = ‘$ Driver_Name’   // incorrect quoting and one space that shouldn't be there
having in mind those errors, your query should be failing with errors, and you are not controlling those errors... suggestions:
- Fix the usage of backtics and quoting in the indicated 2 lines
- echo your raw query and check if you are getting what you want before to execute the query p.e:

Code: Select all

    $sql = "<Here your query string>";
    echo "Final Query : ". $sql;   // echoing your raw query should help you to check for possible errors in the string.
    
    $result = mysql_query($sql) or die("Query Error : " . mysql_error());  // add at least die() to trap any possible error with the query.. note:there are better ways than die()
pradeepcarya
Forum Newbie
Posts: 5
Joined: Tue Nov 08, 2011 4:36 am

Re: internet explorer error-while saving data in excel

Post by pradeepcarya »

hi..thnx for response..

might b i cudn't write full code here bcoz of lengthy lines.
but i am able to run my code correctly.problem is same as i mentioned ion 1st post about excel generating in chrome and internet explorer.
plz guide me to fix that issue...
Post Reply