I am creating a simple report using FPDF which opens fine. I have a link on my php page to generate the report in a new tab.

But after generating the report, when i click to any button or radio box on the php web page, the design view of the page is lost. Instead the html and php code of that page are displayed on that page. I am using dreamweaver. What is the reason behind this? Could some one tell me how to debug this problem?

Thanks

You may follow steps given below. Still if you are not getting out of the problem then paste your code here.

1) The page in which you have written fpdf code for generating pdf, make sure there is no space or enter mark before and after php tags.
2) start your report code like given below.

<?php
	header('Cache-Control: maxage=3600');
	header('Pragma: public');	

	/*
		fpdf source code
	*/
?>

3) If possible write report login in separted page and call that page from report landing page.
4) do not write any echo or html statement in report logic page.
5) In your report calling page (where you are losing html output), check whether you have kept following html code

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

I tried what you have suggested me to do. It still does not work. I am posting my code here !

timesheet.php

<?php
header('Cache-Control: maxage=3600');
header('Pragma: public'); 
include("globals.php");
require('tabletimesheet.php');

$pdf=new PDF_MC_Table();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','',6);

$result=mysql_query("Select ClientVendorID,ClientVendorName,Address,City,State,Zipcode,Country from tblclientvendors;");
$rows = mysql_num_rows($result);

//Table with n rows and 4 columns

$pdf->SetWidths(array(40,25,40,18,9,18,40));
$pdf->SetAligns(array('C','C','C','C','C','C','C'));
$pdf->SetFont('Arial','B',8);   
$pdf->Row(array('Client','Contact','Address','Phone No','Ext','Fax No','Email Address'));

$pdf->SetFont('Arial','',7);
$pdf->SetAligns(array('L','L','L','L','L','L','L'));

for($i=0;$i<$rows;$i++)
{
	$r = mysql_fetch_row($result);

	$address = $r[2]."\n".$r[3]." " .$r[4]." ".$r[5]."  (".$r[6].")";
	$pdf->Row(array($r[1],'',$address,'','','',''));

	$result_sub=mysql_query("Select FirstName,LastName,Phone,Fax,Extension,Email from tblclientvendorcontacts where ClientVendorID='$r[0]' and Active='Y';");
	$rows_subquery = mysql_num_rows($result_sub);

	for($z=0;$z<$rows_subquery;$z++)
	{
	$pdf->SetLineWidth(0.2);
	$r1 = mysql_fetch_row($result_sub);
	$name =$r1[0]." ".$r1[1];
	$pdf->Row1(array('',$name,'',$r1[2],$r1[4],$r1[3],$r1[5]));
	}
	$x = $pdf->GetX();
	$y = $pdf->GetY();
	$y+=2;
	$pdf->SetXY($x,$y);
}
$pdf->Output();
?>

tabletimesheet.php

<?php
header('Cache-Control: maxage=3600');
header('Pragma: public'); 
include("globals.php");
require('fpdf16/fpdf.php');

class PDF_MC_Table extends FPDF
{
var $widths;
var $aligns;

function Header()
{
	$this->Image('CSA_Logo.jpg',5,5,33);
    $this->SetFont('Arial','B',8);
 	$this->SetFillColor(255,255,255);
    $this->Cell(190,10,'TIME SHEET',0,0,'R');
    $this->Ln(6);
	$this->SetFont('Arial','B',8);
		$this->Ln(3);
		$y = $this->GetY();
		$userid =$_GET['userid'];
		$r1=mysql_query("SELECT FirstName,LastName from tbluserlist WHERE UserID= '$userid';");
		$r = mysql_fetch_row($r1);	
		$this->Cell(20,10,'Employee Name: '.$r[0]." ".$r[1],0,0,'L');
		$date =$_GET['date'];
		$this->SetX(10);	$y = $this->SetY($y);
	
	//	$ndate = explode('-',str_replace('-','-',$date));
	//	$date = $ndate[2].'-'.$ndate[0].'-'.$ndate[1];
		
		//$nextdate = date("m-d-Y", strtotime('monday +'.$_SESSION['weekNum'].'week')); 
		//$nextdate = explode('-',str_replace('-','-',$nextdate));
		//$nextdate = $nextdate[2].'-'.$nextdate[0].'-'.$nextdate[1];
						
		$nextdate=Date($date,strtotime("Next Monday"));

//		$nextdate = $date[2].'-'.$date[0].'-'.$date[1];
						
	$this->Cell(190,10,'Dates:'.$date."-".$nextdate,0,0,'R');
	$this->Ln();
}

function Footer()
{
    $this->SetY(-20);
  	 $this->SetFont('Arial','B',7);
	$this->SetLineWidth(0.3);
	$this->Line(10,278,200,278);
	$today = date("F j, Y");    
	$this->Cell(0,10,$today,0,0,'L');
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'R');
}

function SetWidths($w)
{
    //Set the array of column widths
    $this->widths=$w;
}

function SetAligns($a)
{
    //Set the array of column alignments
    $this->aligns=$a;
}

function Row($data)
{
    //Calculate the height of the row
    $nb=0;
    for($i=0;$i<count($data);$i++)
     $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
	 
	$h=5*$nb;
    
	//Issue a page break first if needed
    $this->CheckPageBreak($h);
	$this->SetX(10);

    //Draw the cells of the row
    for($i=0;$i<count($data);$i++)
    {
        $w=$this->widths[$i];
        $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'C';
		
		 //Save the current position
        $x=$this->GetX();
        $y=$this->GetY();
	    //Draw the border
		
        $this->Rect($x,$y,$w,$h);
		
        //Print the text
        $this->MultiCell($w,5,$data[$i],0,$a);

		//Put the position to the right of the cell
        $this->SetXY($x+$w,$y);
	}
    //Go to the next line
    $this->Ln($h);
}


function Row1($data)
{
    //Calculate the height of the row
    $nb=0;
    for($i=0;$i<count($data);$i++)
     $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
	 
	$h=5*$nb;
    
	//Issue a page break first if needed
    $this->CheckPageBreak($h);
	$this->SetX(10);

    //Draw the cells of the row
    for($i=0;$i<count($data);$i++)
    {
        $w=$this->widths[$i];
        $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'C';
        //Save the current position
        $x=$this->GetX();
        $y=$this->GetY();
	
        $this->Rect($x,$y,$w,$h);
       $this->MultiCell($w,5,$data[$i],0,$a);
 $this->SetXY($x+$w,$y);
    }
   $this->Ln($h);
}

function CheckPageBreak($h)
{
       if($this->GetY()+$h>$this->PageBreakTrigger)
        $this->AddPage($this->CurOrientation);
}

function NbLines($w,$txt)
{
   $cw=&$this->CurrentFont['cw'];
    if($w==0)
        $w=$this->w-$this->rMargin-$this->x;
    $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
    $s=str_replace("\r",'',$txt);
    $nb=strlen($s);
    if($nb>0 and $s[$nb-1]=="\n")
        $nb--;
    $sep=-1;
    $i=0;
    $j=0;
    $l=0;
    $nl=1;
    while($i<$nb)
    {
        $c=$s[$i];
        if($c=="\n")
        {
            $i++;
            $sep=-1;
            $j=$i;
            $l=0;
            $nl++;
            continue;
        }
        if($c==' ')
            $sep=$i;
        $l+=$cw[$c];
        if($l>$wmax)
        {
            if($sep==-1)
            {
                if($i==$j)
                    $i++;
            }
            else
                $i=$sep+1;
            $sep=-1;
            $j=$i;
            $l=0;
            $nl++;
        }
        else
            $i++;
    }
    return $nl;
}
}
?>

timerecord.php (This is the php page which displays html contents. The file is big, so i am posting only the header information)

<?php
session_start();
if(isset($_GET['wno']))
$_SESSION['weekNum']=$_GET['wno'];
require("afterlogout.php");
require("globals.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
	<meta http-equiv="Content-Type" content="html; charset=iso-8859-1"/>
	<meta name="description" content=""/>
	<meta name="keywords" content="" />
	<meta name="author" content="" />
	<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
    <style type="text/css">
<!--
.style1 {font-size: 120%}
.style5 {
	font-size: medium;
	font-weight: bold;
}

I tried what you have suggested me to do. It still does not work. I am posting my code here. I have 2 different files for creating reports and the last code is the one having the link to generate the report.Please help me out !

timesheet.php

<?php
header('Cache-Control: maxage=3600');
header('Pragma: public'); 
include("globals.php");
require('tabletimesheet.php');

$pdf=new PDF_MC_Table();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Arial','',6);

$result=mysql_query("Select ClientVendorID,ClientVendorName,Address,City,State,Zipcode,Country from tblclientvendors;");
$rows = mysql_num_rows($result);

$pdf->SetWidths(array(40,25,40,18,9,18,40));
$pdf->SetAligns(array('C','C','C','C','C','C','C'));
$pdf->SetFont('Arial','B',8);   
$pdf->Row(array('Client','Contact','Address','Phone No','Ext','Fax No','Email Address'));

$pdf->SetFont('Arial','',7);
$pdf->SetAligns(array('L','L','L','L','L','L','L'));

for($i=0;$i<$rows;$i++)
{
	$r = mysql_fetch_row($result);
	$address = $r[2]."\n".$r[3]." " .$r[4]." ".$r[5]."  (".$r[6].")";
	$pdf->Row(array($r[1],'',$address,'','','',''));

	$result_sub=mysql_query("Select FirstName,LastName,Phone,Fax,Extension,Email from tblclientvendorcontacts where ClientVendorID='$r[0]' and Active='Y';");
	$rows_subquery = mysql_num_rows($result_sub);

	for($z=0;$z<$rows_subquery;$z++)
	{
	$pdf->SetLineWidth(0.2);
	$r1 = mysql_fetch_row($result_sub);
	$name =$r1[0]." ".$r1[1];
	$pdf->Row1(array('',$name,'',$r1[2],$r1[4],$r1[3],$r1[5]));
	}
	$x = $pdf->GetX();
	$y = $pdf->GetY();
	$y+=2;
	$pdf->SetXY($x,$y);
}
$pdf->Output();
?>

tabletimesheet.php

<?php
header('Cache-Control: maxage=3600');
header('Pragma: public'); 
include("globals.php");
require('fpdf16/fpdf.php');

class PDF_MC_Table extends FPDF
{
var $widths;
var $aligns;

function Header()
{
    $this->Image('CSA_Logo.jpg',5,5,33);
    $this->SetFont('Arial','B',8);
    $this->SetFillColor(255,255,255);
    $this->Cell(190,10,'TIME SHEET',0,0,'R');
    $this->Ln(6);
	$this->SetFont('Arial','B',8);
		$this->Ln(3);
		$y = $this->GetY();
		$userid =$_GET['userid'];
		$r1=mysql_query("SELECT FirstName,LastName from tbluserlist WHERE UserID= '$userid';");
		$r = mysql_fetch_row($r1);	
		$this->Cell(20,10,'Employee Name: '.$r[0]." ".$r[1],0,0,'L');
		$date =$_GET['date'];
		$this->SetX(10);	$y = $this->SetY($y);
	
		$nextdate=Date($date,strtotime("Next Monday"));

	$this->Cell(190,10,'Dates:'.$date."-".$nextdate,0,0,'R');
	$this->Ln();
}

function Footer()
{
    $this->SetY(-20);
  	 $this->SetFont('Arial','B',7);
	$this->SetLineWidth(0.3);
	$this->Line(10,278,200,278);
	$today = date("F j, Y");    
	$this->Cell(0,10,$today,0,0,'L');
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'R');
}

function SetWidths($w)
{
   $this->widths=$w;
}

function SetAligns($a)
{
 $this->aligns=$a;
}

function Row($data)
{
   $nb=0;
    for($i=0;$i<count($data);$i++)
     $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
	 
	$h=5*$nb;
    
	$this->CheckPageBreak($h);
	$this->SetX(10);

    for($i=0;$i<count($data);$i++)
    {
        $w=$this->widths[$i];
        $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'C';
		
	$x=$this->GetX();
        $y=$this->GetY();
	
        $this->Rect($x,$y,$w,$h);
	  $this->MultiCell($w,5,$data[$i],0,$a);
	  $this->SetXY($x+$w,$y);
	}
     $this->Ln($h);
}


function Row1($data)
{
  $nb=0;
    for($i=0;$i<count($data);$i++)
     $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
	 
	$h=5*$nb;
    
	$this->CheckPageBreak($h);
	$this->SetX(10);

    for($i=0;$i<count($data);$i++)
    {
        $w=$this->widths[$i];
        $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'C';
        $x=$this->GetX();
        $y=$this->GetY();
	
        $this->Rect($x,$y,$w,$h);
       $this->MultiCell($w,5,$data[$i],0,$a);
 $this->SetXY($x+$w,$y);
    }
   $this->Ln($h);
}

function CheckPageBreak($h)
{
       if($this->GetY()+$h>$this->PageBreakTrigger)
        $this->AddPage($this->CurOrientation);
}

function NbLines($w,$txt)
{
   $cw=&$this->CurrentFont['cw'];
    if($w==0)
        $w=$this->w-$this->rMargin-$this->x;
    $wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
    $s=str_replace("\r",'',$txt);
    $nb=strlen($s);
    if($nb>0 and $s[$nb-1]=="\n")
        $nb--;
    $sep=-1;
    $i=0;
    $j=0;
    $l=0;
    $nl=1;
    while($i<$nb)
    {
        $c=$s[$i];
        if($c=="\n")
        {
            $i++;
            $sep=-1;
            $j=$i;
            $l=0;
            $nl++;
            continue;
        }
        if($c==' ')
            $sep=$i;
        $l+=$cw[$c];
        if($l>$wmax)
        {
            if($sep==-1)
            {
                if($i==$j)
                    $i++;
            }
            else
                $i=$sep+1;
            $sep=-1;
            $j=$i;
            $l=0;
            $nl++;
        }
        else
            $i++;
    }
    return $nl;
}
}
?>

timerecord.php (This is the php page which displays html contents. The file is big, so i am posting only the header information)

<?php
session_start();
if(isset($_GET['wno']))
$_SESSION['weekNum']=$_GET['wno'];
require("afterlogout.php");
require("globals.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
	<meta http-equiv="Content-Type" content="html; charset=iso-8859-1"/>
	<meta name="description" content=""/>
	<meta name="keywords" content="" />
	<meta name="author" content="" />
	<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
    <style type="text/css">
<!--
.style1 {font-size: 120%}
.style5 {
	font-size: medium;
	font-weight: bold;
}

I am highlighting the change(added content="text/html" in meta tag instead of only "html") in following line for your calling page. But for debugging I need your table, sample data (which you may export from phpmyadmin), and all related source files at least The bigger HTML calling page.
You may make a zip file for this files and upload here.
Also try removing media="screen" attribute from the link tag.

<?phpsession_start();if(isset($_GET['wno']))$_SESSION['weekNum']=$_GET['wno'];require("afterlogout.php");require("globals.php");?><html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"><head>	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>	<meta name="description" content=""/>	<meta name="keywords" content="" />	<meta name="author" content="" />	<link rel="stylesheet" type="text/css" href="style.css" media="screen" />    <style type="text/css"><!--.style1 {font-size: 120%}.style5 {	font-size: medium;	font-weight: bold;}<?php
session_start();
if(isset($_GET['wno']))
$_SESSION['weekNum']=$_GET['wno'];
require("afterlogout.php");
require("globals.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>


[bold]	<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>[bold]



	<meta name="description" content=""/>
	<meta name="keywords" content="" />
	<meta name="author" content="" />
	<link rel="stylesheet" type="text/css" href="style.css" media="screen" />
    <style type="text/css">
<!--
.style1 {font-size: 120%}
.style5 {
	font-size: medium;
	font-weight: bold;
}

Thanks for your help. I tried doing that but the problem still persists. I am attaching some code,report code and table data in this reply. Please let me know if you are able to figure it out. It will be of great help !

Thanks again !

My doubts
I have gone through your code, I think there is some problem with navigation. You site flow looks little bit confusing. Some questions are there in my mind.
1) you send me two timesheet.php one is outside and other in report folder which is actually containing fpdf source. but this "report/timesheet.php" file is never called.
2) you have also mention expensesheet.php in calling page. but it is not there in zip file.
please clear my above two doubts.

My observations
1) You are having one form tag but you have not specified action attribute.
2) in your first post of this thread you said, you are opening the report in new window but, here in form tag you have not specified target attribute.
3) on submitting your form you are changing self.location. I dont favour this.

My suggesstions

following are steps that i follow in my fpdf pages.

Report calling page

<script lang='javascript'>
	function validate()
	{
		/*
		here check using javascript code
		whether user passed all parameters in
		required format
		*/
		document.frm.submit();
	}
</script>

<form=frm method=post action="fpdfreport.php" target="_blank">
<input type=text name=para1>
<input type=text name=para2>
<input type=text name=para3>
<input type=button onclick='validate()'>
</form>

fpdf Report page algorithm (only php code no html)

1) execute query=mysql_query("select * from table where p1='$_POST[para1]' and p2='$_POST[para2]' and p3='$_POST[para3]');

2 run query

3) set fpdf object using result

4) output fpdf->output

I know there is some problem with the navigation, i am trying to figure it out since long.

1. reports/timesheet.php is called. I have a link named "View Time Sheet Report" which calls this php page.
2. Yes, there is expensesheet.php. Sorry, i forgot to zip it in the folder.

I am using only 1 form for all the actions to be performed through timesheet.php. That is why i have not mentioned anything in the Action attribute. I am using onClick() attribute with every form element if i want to navigate to a different page. And then javascript does the checking and performs the redirection.

But the problem with navigation is that in most of the cases, i need to have document.write() above self.location(URL) code.That is again a mystery to me as it really does a lot of loading and a white screen is flashed every time i press any button or form element. Why is it that document.write() is needed for some javascript functions and not for others?

I am redirecting the php page to open the report not through the Form attribute, but through an href link, thats why the form tag does not have any specific attribute.

I know that there are some flaws in this code which makes it more hard to debug. But i really appreciate you helping me out with this !

Thanks !

I tried my best to debug but your case is needed to debug in realtime environment. At least you try to open report in new window and not same window. If you still need my help. Then you need to upload zip files of all related source files and database scripts.
One more thing you can do that check your pages in different browsers may be in mozilla and chrome.
I am only helping you because it is difficult to find much online help on fpdf and I struggled a lot for fpdf before

Thanks. I am trying to debug it for some time. I would let you know if i need your help further. Could you give me your mail id?

commented: :( +0

Could you give me your mail id?

Please do not ask for help via email. Read the forum rules about Keeping it on the Site.

I am sorry. I will post my doubts on the forum itself !

I tried to modify timesheet.php page so that i can have multiple forms and associate action with them.
One doubt:

<script lang='javascript'>
      function validate()
      {
      document.frm.submit();
      }

     <form=frm method=post action="fpdfreport.php" target="_blank">
      <input type=text name=para1>
      <input type=text name=para2>
      <input type=button onclick='validate()'>
      </form>

This code is used when i am not reading form values and redirecting to a fixed URL. What would the code be if i want to read a value from list box in a javascript function and then decide my target URL and then submit it with form action?

This is my current code:

function reloaduseridndate(ndate,wno)
{
var val=userform.employeeid.options[userform.employeeid.options.selectedIndex].value;	
document.write();
self.location='timesheet.php?userid='+val+'&ndate='+ndate+'&wno='+wno;
}

What changes needs to be done?

In my previous posts I told you not to use self.location
I am giving you code according to your pages. also you have not to create multiple forms
you can do it using only one form. You need to change your code in fpdfreport.php, use $_REQUEST or $_POST instead of $_GET.
pLEAESE do not build urls anymore, just post the form. also avoid self page posting

code for reportcaller.php

<script lang='javascript'>


      function validate(reportno)
      {
	      if(reportno==1)
		{
			if(document.frm.userid.value=="")
			{
				alert('select userid');
				return false;

			}
			if(document.frm.wno.value=="")
			{
				alert('select wno');
				return false;

			}
			if(document.frm.ndate.value=="")
			{
				alert('enter date');
				return false;

			}
			document.frm.action="timesheet.php";
		}

	  
              if(reportno==2)
		{
			if(document.frm.para1.value=="")
			{
				alert('enter para1');
				return false;

			}
			if(document.frm.para2.value=="")
			{
				alert('enter para1');
				return false;

			}

			document.frm.action="expensesheet.php";
		}

	
	      document.frm.submit();
      }
</script>

     <form=frm method=post  target="_blank">
      
	user ID <select name=USERID>
		<option value="">select user
		<option value=231>ADITI
		<option value=342>UPENDRA
		<option value=423>DANIWEB
	</select>

	Date <input type=text name=ndate>

	wno <select name=wno>
		<option value="">select wno
		<option value=1>1
		<option value=2>2
		<option value=3>3
	</select>
      para 1 <input type=text name=para1>
      para 2 <input type=text name=para2>
      <input type=button name=btntime value='Time Report' onclick='validate(1)' >

      <input type=button name=btnexpense value='Expense Report' onclick='validate(2)' >
   </form>

Form will post whole data to your actual fpdf report file. do not call same file and do not set url. You only take care in validate
function that user has selected required parameters or not.

algorithm for timesheet.php

1) execute query=mysql_query("select * from table where userid='$_POST[userid]' and date='$_POST[ndate]' and wno='$_POST[wno]'); 
2 run query 
3) set fpdf object using result 
4) output fpdf->output

algorithm for expensesheet.php

1) execute query=mysql_query("select * from table where p1='$_POST[para1]' and p2='$_POST[para1]'); 
2 run query 
3) set fpdf object using result 
4) output fpdf->output
Be a part of the DaniWeb community

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