Question : How Do I Generate An MS Word (.doc) File On The Fly Using PHP

Greetings -

I am having difficulty generating MS Word (.doc) files on the fly using PHP and sessions, and sure could use some expert help!

Note:  I am not expert in PHP, XML, etc.

I have a multi-page form (written in PHP), and use Sessions to pass data from one form page to the next.  Here, for your reference, is the code being used on each of the form's pages:

<?php
session_start();
header("Cache-control: private");
include ('fieldforwarder.php');
?>

The following bit of code is being used atop the PHP page that renders an online display of form content:

<?php
session_start();
header("Cache-control: private");
include ('fieldforwarder.php');

while (list($key, $value) = each($_SESSION))
{
  $page[$key] = $value;
}

if (isset($_POST) && !empty($_POST))
{
    // addslashes to SESSION values
  reset($_SESSION);
  while (list($key, $value) = each($_SESSION))
    $_SESSION[$key] = addslashes($value);
   
  exit;
}

?>

All of the above code works well.   Note:  there are three versions (accessible via hyperlinks on the first display page) of the original display page.  Each of these pages is written in PHP, and they work wonderfully.  However, when I attempt to save each of the display pages (for the very first time), MS Word opens to a blank page.  (Not the desired result).  Yet, when I click on the second or third version of the display page, and attempt to save the respective files as MS Word documents - it works.  Only then - can I return to the first version and save it as an MS Word file.

Please note that LINUX is running on my server.

I'm open to any solution that remedies this situation.  If you have a solution, please provide code that resolves the issue.  I'm rather anxious to an immediate solution, and will focus on learning the script in a couple days (following implementation).

Many thanks for the help.

Mary -

Answer : How Do I Generate An MS Word (.doc) File On The Fly Using PHP

ok, I got it working

SELECT
<output name="year" replace="(YEAR(t.time))" />AS year,
<output name="month" replace="(MONTHNAME(t.time))" chart="k" />AS month,
<output name="invoice" replace="(SUM(t.invoice))" chart="l" data="float" />AS invoice,
<output name="payments" replace="(SUM(t.payment))" chart="l" data="float" />AS payments,
<output name="lights" replace="CAST((SUM(service)) AS Decimal(8,2))" chart="d" data="float" />AS lights,
<output name="lights2" replace="CAST((SUM(service2)) AS Decimal(8,2))" chart="d" data="float" />AS lights2,
<output name="hose" replace="CAST((SUM(hose)) AS Decimal(8,2))" chart="d" data="float" />AS hose
FROM transac t
LEFT JOIN (SELECT v.datetime AS datetime, (v.quantity * s.charges) AS service FROM invitem v LEFT JOIN service s ON s.idservice = v.idservice WHERE s.idservice = 'PARTS-LIGHTS-VBFG-2' GROUP BY v.datetime) z ON z.datetime = t.time
LEFT JOIN (SELECT v.datetime AS datetime, (v.quantity * s.charges) AS service2 FROM invitem v LEFT JOIN service s ON s.idservice = v.idservice WHERE s.idservice = 'PARTS-LIGHT-FGRT-1' GROUP BY v.datetime) y ON y.datetime = t.time
LEFT JOIN (SELECT v.datetime AS datetime, (v.quantity * s.charges) AS hose FROM invitem v LEFT JOIN service s ON s.idservice = v.idservice WHERE s.idservice = 'UTILSRUBBERHOSE657' GROUP BY v.datetime) w ON w.datetime = t.time
WHERE DATE(time) between 'a year ago' AND DATE(NOW())
GROUP BY MONTHNAME(t.time)
Random Solutions  
 
programming4us programming4us