phpword alert box

Dec 2, 2010 at 1:37 AM

my code like this but i don't know why my file with no data when i use alert box

anyone help me please!!!!!!!!!!

 

require_once '../PHPWord.php';
include_once('../connection.php');

$traing_code=@$_REQUEST['id'];
$query=mysql_query("SELECT * FROM training_training where TCode=$traing_code");
$row=mysql_fetch_row($query);

$sql_ta=mysql_query("select * from training_acitivies where TA_Code=$row[2]");
$ta_des=mysql_fetch_row($sql_ta);

$sql_pro=mysql_query("select * from training_programe where pro_code=$row[1]");
$pro=mysql_fetch_row($sql_pro);

$sql_user=mysql_query("select * from pro_person where Code=$row[16]");
$user=mysql_fetch_row($sql_user);

$sql_trainner=mysql_query("select * from training_trainner where Code=$row[0]");
$trainner=mysql_fetch_row($sql_trainner);

$sql_trainee=mysql_query("select * from training_categories where CCode=$row[0]");
$trainee=mysql_fetch_row($sql_trainee);

$sql_type=mysql_query("select * from training_type where TYPE_CODE=$row[9]");
$type=mysql_fetch_row($sql_type);


$sql_provider=mysql_query("select * from training_provider where Pro_Code=$row[8]");
$provider=mysql_fetch_row($sql_provider);

$PHPWord = new PHPWord();

$document = $PHPWord->loadTemplate('training_report.docx');

$document->setValue('pro_code',$traing_code);
$document->setValue('strdate', $row[4]);
$document->setValue('enddate',$row[5]);
$document->setValue('des', $row[3]);
$document->setValue('usaid_trainee',$row[18]);
$document->setValue('usaid_instr', $row[17]);
$document->setValue('usaid_travel',$row[19]);
$document->setValue('type',$type[1]);
$document->setValue('provider',$provider[1]);
//$document->save('123.docx');
header('Content-Type: application/vnd.ms-word');
header('Content-Disposition: attachment;filename="myfile.docx"');
header('Cache-Control: max-age=0');

Dec 7, 2010 at 2:34 PM

Try this code at the end:

$fileName = 'my_file_name';
header('Content-Type: application/vnd.ms-word');
header('Content-Disposition: attachment;filename="'.$fileName.'.docx"');  // set the file name
header('Cache-Control: max-age=0');

// Save and output file to browser
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('php://output');
exit;     //you MUST have the exit!