Hello all: I have a small script that will present options to a user, and from those options will export data into an Excel spreadsheet. This seems to work correctly, but the problem is that the user interface page does not get updated after the download.

Here is an example: I have an element on the form called $frmErrMsg, which I set to a text value and display it on the page. It is controlled by another variable called $frmErrorLevel(in this case it is set to either a 0 or 1). On initial page load I set the $frmErrorLevel variable to a 1 and the message displays.

When I process the Excel file, I reset the $frmErrorLevel = 0, but the message does not clear.

Obviously the form is not reloading after the Excel file is output (due to the extra header???). is there a better technique for handling this?

Here is some code:

  include_once $_SERVER['DOCUMENT_ROOT'] .
  include_once $_SERVER['DOCUMENT_ROOT'] .
  include_once $_SERVER['DOCUMENT_ROOT'] .
  if(isset($_POST['action']) && $_POST['action']=='submitted')
       // this will call the ExcelXML.php scripts and output the data to Excel
   else $frmErrorLevel=1;
   $frmErrMsg = 'Error retrieving Carrier Data';
   include ('form.html.php');

here is the form.html.php

        include_once $_SERVER['DOCUMENT_ROOT'] .'/inc/standardFunctions.inc.php'; 
<!DOCTYPE html>
<html lang="en">
        <meta charset="utf-8">
        <title>Export Trucking Data</title>
        <h1>Export Data</h1>
        <form action="" method="post">
        <?php   if($frmErrorLevel>0)
                    echo '<font color=#CC6600 size=+1>'.$frmErrMsg.'</font><br><br>';
        <table width="650" border="0">
                <font size="+3">Data Export Options</font>
                        if($frmErrorLevel==1) print '<img src= ..\..\images\rdx.gif>'; 
                        else echo "&nbsp"; 
                <td width="275">Carrier table data</td>
                <td width="100"><input name="ExportCarrier" type="submit" value="Submit"></td>
                <td> <div align="center"> &nbsp;</div></td>

            <input type="hidden" name="action" value="submitted" />

and finally, the Excel output header

function save($filename, $download=false, $download_filename="")
        if (!$download)
            return $this->domXML->save($filename);
        elseif ($this->domXML->save($filename))
            $FileInfo = pathinfo(filename);
            // fix for IE catching or PHP bug issue 
            header("Pragma: public"); 
            header("Expires: 0"); // set expiration time 
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");  
            // browser must download file from server instead of cache 
            // force download dialog 
            header("Content-Type: application/force-download"); 
            header("Content-Type: application/octet-stream"); 
            header("Content-type: application/x-msexcel");
            header("Content-Type: application/download"); 
            // use the Content-Disposition header to supply a recommended filename and  
            // force the browser to display the save dialog.
            if ($download_filename == "")
                $download_filename = "download.xls";
            header("Content-Disposition: attachment; filename=".$download_filename.";"); 
            header("Content-Transfer-Encoding: binary"); 
            header("Content-Length: ".filesize($filename)); 
            return true;
        return false;

What is \inc\magicquotes.inc.php and /inc/base.inc.php and /admin/export/excel-xml.php and /inc/standardFunctions.inc.php . Simplify your problem and the include files and you might get an answer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.