PHP: Export to PDF

Hi all,
I have this code (rpt_invalid.php )

<?php  
//ob_start();
session_start();
require('../verification_branch/pdf/fpdf.php');
include_once('../connect.php');  
?>
 
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<body>
<?php
//session_start();

//$header=array('Id','Name','IdentifyNo','Account','Date','sothe','cardid');

      $i=0;
      $j=0;

      //$q = 'select * from cards where conf = "1" and datec="'.$_GET['date'].'" and bank = "'.$_SESSION['branch'].'" order by id asc';
      if ($_SESSION['type'] == '4')
      {
            $q = 'select * from `cards` where `conf`="3" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and ((`reason` = "InvalidPicture") or (`reason` = "InvalidInfo"))and `userid` in (select `id` from `users` where `Country` = "'.$_SESSION['branch'].'") ORDER BY `cards`.`id` ASC';
      }
      elseif ($_SESSION['type'] == '5')
      {
            $q = 'select * from `cards` where `conf`="7" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and `reason` = "InvalidPicture_KSV" and `userid` in (select `id` from `users` where `Country` = "'.$_SESSION['branch'].'") ORDER BY `cards`.`id` ASC';
      }

      $r = mysql_query($q);
      //echo ($q);
      //echo ($r);
      echo mysql_error();

      $pdf=new FPDF('l','mm','A4');
      $i = 0;
//for($i=0;$i<$date.length;$i++){

    $pdf->AddPage();
      $pdf->SetFont('times','',10);
      //$pdf->Cell(35,4,'L?NH YÊU C?U IN TH?');
      $pdf->Cell(10,5,'STT');
      $pdf->Cell(25,5,'Ho ten KH');
      $pdf->Cell(35,5,'So CMND');
    $pdf->Cell(36,5,'So Tai khoan');
      $pdf->Cell(37,5,'So the');
      $pdf->Cell(38,5,'So tham chieu anh thiet ke');
      $pdf->Cell(39,5,'Ngay/gio');
      $pdf->Cell(43,5,'Ghi chu');
      //$pdf->Cell(45,5,'Ly do');
      while($w = mysql_fetch_array($r)){
      $i++;
      //echo ($w);
      $q2 = 'select * from users where id="'.$w['userId'].'"';
      $r2 = mysql_query($q2);
      $row2 = mysql_fetch_array($r2);
      
      $date = array($i,''.$row2['Salutation'].$row2['Firstname'].''.$row2['Lastname'].'',$row2['IdentifyNo'],$row2['account'],$w['dateC'],$w['sothe'],$w['id']);
      
      
      /*for($j=0;$j<2;$j++){
            $pdf->Cell(10,5,$header[$j].': '.$date[$j]);
            $pdf->Cell(40,5,$i[$j]);*/
        $pdf->Ln(7);
            $pdf->Cell(10,7,$i);
      
            $pdf->Cell(25,7,''.$row2['Salutation'].$row2['Firstname'].' '.$row2['Lastname'].'');
            $pdf->Cell(35,7,''.$row2['IdentifyNo'].'');
            $pdf->Cell(36,7,''.$row2['account'].'');
          $pdf->Cell(37,7,''.$w['sothe'].'');
            $pdf->Cell(38,7,''.$w['id'].'');
            $pdf->Cell(41,7,''.$w['dateC'].'');
            //$pdf->Cell(43,7,' ');
            //$pdf->Cell(45,7,''.$w['reasondetail'].'');
        $pdf->Ln(4);
      /*}*/
      /*
      $pdf->Cell(40,5,'Original Image:');
      $pdf->Ln();
      $pdf->Cell(40,5,'http://www.me/card/app/files/userImages/'.$w['src']);
      $pdf->Ln();
      $pdf->Image('../../../app/files/userImages/'.$w['src']);
      $pdf->Ln();
      $pdf->Cell(40,5,'Users Image Image:');
      $pdf->Ln();
      $pdf->Cell(40,5,'http://www/card/app/files/userImages/'.$w['src2']);
      $pdf->Ln();
      $pdf->Image('../../../app/files/userImages/'.$w['src2']);
      $pdf->Ln();
      $pdf->Cell(40,5,'Bank Accept:');
      $pdf->Ln();
      $pdf->Cell(40,5,$w['bank']);
      $pdf->Ln();
      $pdf->Cell(40,5,'Code:');
      $pdf->Ln();
      $pdf->Cell(40,5,$w['id']);
      $pdf->Ln(); */

      }
$pdf->Cell(10,11,'Date Printed:');
$pdf->Ln(4);

date_default_timezone_set('Bangkok, Hanoi, Jakarta');
putenv("Bangkok, Hanoi, Jakarta");

$pdf->Cell(10,15,gmdate("d/m/Y h:i A", time() + 7 * 3600));
$pdf->Ln(4);
/*$pdf->Cell(20,19,'Maker');
$pdf->Ln(4);
$pdf->Cell(41,19,'Checker');*/
$pdf->Output();

?>

</body>
</html>

After running this code, I have following err:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php:1) in D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php:1) in D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\pdf\fpdf.php on line 1017
FPDF error: Some data has already been output, can't send PDF file

Pls help me.

fpdf.php
LVL 5
dinhchung82Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shinesh PremrajanEngineering ManagerCommented:
remove the HTML code from the page, you dont need the HTML tags while outputting the PDF.
Refer the attached file.

Hope this helps
<?php  
//ob_start();
session_start();
require('../verification_branch/pdf/fpdf.php');
include_once('../connect.php');  

//session_start();

//$header=array('Id','Name','IdentifyNo','Account','Date','sothe','cardid');

      $i=0;
      $j=0;

      //$q = 'select * from cards where conf = "1" and datec="'.$_GET['date'].'" and bank = "'.$_SESSION['branch'].'" order by id asc';
      if ($_SESSION['type'] == '4')
      {
            $q = 'select * from `cards` where `conf`="3" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and ((`reason` = "InvalidPicture") or (`reason` = "InvalidInfo"))and `userid` in (select `id` from `users` where `Country` = "'.$_SESSION['branch'].'") ORDER BY `cards`.`id` ASC';
      }
      elseif ($_SESSION['type'] == '5')
      {
            $q = 'select * from `cards` where `conf`="7" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and `reason` = "InvalidPicture_KSV" and `userid` in (select `id` from `users` where `Country` = "'.$_SESSION['branch'].'") ORDER BY `cards`.`id` ASC';
      }

      $r = mysql_query($q);
      //echo ($q);
      //echo ($r);
      echo mysql_error();

      $pdf=new FPDF('l','mm','A4');
      $i = 0;
//for($i=0;$i<$date.length;$i++){

    $pdf->AddPage();
      $pdf->SetFont('times','',10);
      //$pdf->Cell(35,4,'L?NH YÊU C?U IN TH?');
      $pdf->Cell(10,5,'STT');
      $pdf->Cell(25,5,'Ho ten KH');
      $pdf->Cell(35,5,'So CMND');
    $pdf->Cell(36,5,'So Tai khoan');
      $pdf->Cell(37,5,'So the');
      $pdf->Cell(38,5,'So tham chieu anh thiet ke');
      $pdf->Cell(39,5,'Ngay/gio');
      $pdf->Cell(43,5,'Ghi chu');
      //$pdf->Cell(45,5,'Ly do');
      while($w = mysql_fetch_array($r)){
      $i++;
      //echo ($w);
      $q2 = 'select * from users where id="'.$w['userId'].'"';
      $r2 = mysql_query($q2);
      $row2 = mysql_fetch_array($r2);
      
      $date = array($i,''.$row2['Salutation'].$row2['Firstname'].''.$row2['Lastname'].'',$row2['IdentifyNo'],$row2['account'],$w['dateC'],$w['sothe'],$w['id']);
      
      
      /*for($j=0;$j<2;$j++){
            $pdf->Cell(10,5,$header[$j].': '.$date[$j]);
            $pdf->Cell(40,5,$i[$j]);*/
        $pdf->Ln(7);
            $pdf->Cell(10,7,$i);
      
            $pdf->Cell(25,7,''.$row2['Salutation'].$row2['Firstname'].' '.$row2['Lastname'].'');
            $pdf->Cell(35,7,''.$row2['IdentifyNo'].'');
            $pdf->Cell(36,7,''.$row2['account'].'');
          $pdf->Cell(37,7,''.$w['sothe'].'');
            $pdf->Cell(38,7,''.$w['id'].'');
            $pdf->Cell(41,7,''.$w['dateC'].'');
            //$pdf->Cell(43,7,' ');
            //$pdf->Cell(45,7,''.$w['reasondetail'].'');
        $pdf->Ln(4);
      /*}*/
      /*
      $pdf->Cell(40,5,'Original Image:');
      $pdf->Ln();
      $pdf->Cell(40,5,'http://www.me/card/app/files/userImages/'.$w['src']);
      $pdf->Ln();
      $pdf->Image('../../../app/files/userImages/'.$w['src']);
      $pdf->Ln();
      $pdf->Cell(40,5,'Users Image Image:');
      $pdf->Ln();
      $pdf->Cell(40,5,'http://www/card/app/files/userImages/'.$w['src2']);
      $pdf->Ln();
      $pdf->Image('../../../app/files/userImages/'.$w['src2']);
      $pdf->Ln();
      $pdf->Cell(40,5,'Bank Accept:');
      $pdf->Ln();
      $pdf->Cell(40,5,$w['bank']);
      $pdf->Ln();
      $pdf->Cell(40,5,'Code:');
      $pdf->Ln();
      $pdf->Cell(40,5,$w['id']);
      $pdf->Ln(); */

      }
$pdf->Cell(10,11,'Date Printed:');
$pdf->Ln(4);

date_default_timezone_set('Bangkok, Hanoi, Jakarta');
putenv("Bangkok, Hanoi, Jakarta");

$pdf->Cell(10,15,gmdate("d/m/Y h:i A", time() + 7 * 3600));
$pdf->Ln(4);
/*$pdf->Cell(20,19,'Maker');
$pdf->Ln(4);
$pdf->Cell(41,19,'Checker');*/
$pdf->Output();
?>

Open in new window

0
dinhchung82Author Commented:
The same error:
 
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php:1) in D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php:1) in D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\pdf\fpdf.php on line 1017
FPDF error: Some data has already been output, can't send PDF file
0
Shinesh PremrajanEngineering ManagerCommented:
The error is due to the session_start in the first line of code. Updated the code with the ob_start and ob_end functionality,

Hope this helps.
<?php  

ob_start();
session_start();
require('../verification_branch/pdf/fpdf.php');
include_once('../connect.php');  

//$header=array('Id','Name','IdentifyNo','Account','Date','sothe','cardid');

      $i=0;
      $j=0;

      //$q = 'select * from cards where conf = "1" and datec="'.$_GET['date'].'" and bank = "'.$_SESSION['branch'].'" order by id asc';
      if ($_SESSION['type'] == '4')
      {
            $q = 'select * from `cards` where `conf`="3" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and ((`reason` = "InvalidPicture") or (`reason` = "InvalidInfo"))and `userid` in (select `id` from `users` where `Country` = "'.$_SESSION['branch'].'") ORDER BY `cards`.`id` ASC';
      }
      elseif ($_SESSION['type'] == '5')
      {
            $q = 'select * from `cards` where `conf`="7" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and `reason` = "InvalidPicture_KSV" and `userid` in (select `id` from `users` where `Country` = "'.$_SESSION['branch'].'") ORDER BY `cards`.`id` ASC';
      }

     echo $q;

     $q= ob_end_flush();

      $r = mysql_query($q);
      //echo ($q);
      //echo ($r);
      echo mysql_error();


      $pdf=new FPDF('l','mm','A4');
      $i = 0;
//for($i=0;$i<$date.length;$i++){

    $pdf->AddPage();
      $pdf->SetFont('times','',10);
      //$pdf->Cell(35,4,'L?NH YÊU C?U IN TH?');
      $pdf->Cell(10,5,'STT');
      $pdf->Cell(25,5,'Ho ten KH');
      $pdf->Cell(35,5,'So CMND');
    $pdf->Cell(36,5,'So Tai khoan');
      $pdf->Cell(37,5,'So the');
      $pdf->Cell(38,5,'So tham chieu anh thiet ke');
      $pdf->Cell(39,5,'Ngay/gio');
      $pdf->Cell(43,5,'Ghi chu');
      //$pdf->Cell(45,5,'Ly do');
      while($w = mysql_fetch_array($r)){
      $i++;
      //echo ($w);
      $q2 = 'select * from users where id="'.$w['userId'].'"';
      $r2 = mysql_query($q2);
      $row2 = mysql_fetch_array($r2);
      
      $date = array($i,''.$row2['Salutation'].$row2['Firstname'].''.$row2['Lastname'].'',$row2['IdentifyNo'],$row2['account'],$w['dateC'],$w['sothe'],$w['id']);
      
      
      /*for($j=0;$j<2;$j++){
            $pdf->Cell(10,5,$header[$j].': '.$date[$j]);
            $pdf->Cell(40,5,$i[$j]);*/
        $pdf->Ln(7);
            $pdf->Cell(10,7,$i);
      
            $pdf->Cell(25,7,''.$row2['Salutation'].$row2['Firstname'].' '.$row2['Lastname'].'');
            $pdf->Cell(35,7,''.$row2['IdentifyNo'].'');
            $pdf->Cell(36,7,''.$row2['account'].'');
          $pdf->Cell(37,7,''.$w['sothe'].'');
            $pdf->Cell(38,7,''.$w['id'].'');
            $pdf->Cell(41,7,''.$w['dateC'].'');
            //$pdf->Cell(43,7,' ');
            //$pdf->Cell(45,7,''.$w['reasondetail'].'');
        $pdf->Ln(4);
      /*}*/
      /*
      $pdf->Cell(40,5,'Original Image:');
      $pdf->Ln();
      $pdf->Cell(40,5,'http://www.me/card/app/files/userImages/'.$w['src']);
      $pdf->Ln();
      $pdf->Image('../../../app/files/userImages/'.$w['src']);
      $pdf->Ln();
      $pdf->Cell(40,5,'Users Image Image:');
      $pdf->Ln();
      $pdf->Cell(40,5,'http://www/card/app/files/userImages/'.$w['src2']);
      $pdf->Ln();
      $pdf->Image('../../../app/files/userImages/'.$w['src2']);
      $pdf->Ln();
      $pdf->Cell(40,5,'Bank Accept:');
      $pdf->Ln();
      $pdf->Cell(40,5,$w['bank']);
      $pdf->Ln();
      $pdf->Cell(40,5,'Code:');
      $pdf->Ln();
      $pdf->Cell(40,5,$w['id']);
      $pdf->Ln(); */

      }
$pdf->Cell(10,11,'Date Printed:');
$pdf->Ln(4);

date_default_timezone_set('Bangkok, Hanoi, Jakarta');
putenv("Bangkok, Hanoi, Jakarta");

$pdf->Cell(10,15,gmdate("d/m/Y h:i A", time() + 7 * 3600));
$pdf->Ln(4);
/*$pdf->Cell(20,19,'Maker');
$pdf->Ln(4);
$pdf->Cell(41,19,'Checker');*/
$pdf->Output();
?>

Open in new window

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

dinhchung82Author Commented:
I have tried with ob_start(); but when I use ob_start();,I have this err:
Query was empty
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php on line 46
FPDF error: Some data has already been output, can't send PDF file
0
dinhchung82Author Commented:
Hi all,
I fix all the above, my error now is:
 
Warning: Cannot modify header information - headers already sent by (output started at D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php:1) in D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\pdf\fpdf.php on line 1017
FPDF error: Some data has already been output, can't send PDF file
 
Pls help me
0
Shinesh PremrajanEngineering ManagerCommented:
You are getting the error "Query was empty" because $q is having no value passed from the ob_end_flush()

The trick to work around is just disable the session_start() and all the $_session variables referenced in the code, you will notice that PDF is working like a charm. Hence for the PDF and the session to work together we are using the ob_start.

To Resolve this,

You will notice that in the code we have this
    echo $q;
     $q= ob_end_flush();

Place a debugging information here something like

    echo $q;
    $q= ob_end_flush();

    echo $q;  // should display the query something like select * from `cards` where ....
    exit(); //this will stop the application, and should display the SQL query, If you are able to see that, then just disable this exit()

If you able to get the $q values then your script will start working.


Hope this helps


0
dinhchung82Author Commented:
sorry, but I have fixed this.
my error now is:

Warning: Cannot modify header information - headers already sent by (output started at D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php:1) in D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\pdf\fpdf.php on line 1017
FPDF error: Some data has already been output, can't send PDF file

The fpdf.php as attacted
Pls help me
0
Shinesh PremrajanEngineering ManagerCommented:
I think you are mistaken by the errors that at not appearing in the page, since you had enabled a ob_start() the error disapeared.

however you are usnig the session, you will always get this error..
0
dinhchung82Author Commented:
sorry, I already used ob_start()
0
Shinesh PremrajanEngineering ManagerCommented:
try the attached code.. and if you getting the value of $q then we can resolve the problem.
<?php  

ob_start();
session_start();
require('../verification_branch/pdf/fpdf.php');
include_once('../connect.php');  

//$header=array('Id','Name','IdentifyNo','Account','Date','sothe','cardid');

      $i=0;
      $j=0;

      //$q = 'select * from cards where conf = "1" and datec="'.$_GET['date'].'" and bank = "'.$_SESSION['branch'].'" order by id asc';
      if ($_SESSION['type'] == '4')
      {
            $q = 'select * from `cards` where `conf`="3" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and ((`reason` = "InvalidPicture") or (`reason` = "InvalidInfo"))and `userid` in (select `id` from `users` where `Country` = "'.$_SESSION['branch'].'") ORDER BY `cards`.`id` ASC';
      }
      elseif ($_SESSION['type'] == '5')
      {
            $q = 'select * from `cards` where `conf`="7" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and `reason` = "InvalidPicture_KSV" and `userid` in (select `id` from `users` where `Country` = "'.$_SESSION['branch'].'") ORDER BY `cards`.`id` ASC';
      }

     echo $q;

     $q= ob_end_flush();

echo "Value of q:".$q." #";

exit();

?>

Open in new window

0
dinhchung82Author Commented:
hi,
When I used  ob_start(); , variable  $_SESSION['type']  don't have value.
So that I used $_POST['type'] , replace $_SESSION['type'] . I got the value of $_POST['type']  & then $q return value.
But I still have following err and can't export to PDF:
Warning: Cannot modify header information - headers already sent by (output started at D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php:1) in D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\pdf\fpdf.php on line 1017
FPDF error: Some data has already been output, can't send PDF file
 
0
Shinesh PremrajanEngineering ManagerCommented:
Check for any blank spaces in the top of the page, also just disable the session_start() and see if you are getting the PDF generated.
0
VisionCommented:
You cannot use the session_start() (thus no session variables) with FPDF. If you have access to a DB I'd recommend sending a GUID in the query string that points back to the DB for session pieces needed.
0
dinhchung82Author Commented:
Now my code here:

<?php  
ob_start();
//session_start();
require('../verification_branch/pdf/fpdf.php');
include_once('../connect.php');  
//$header=array('Id','Name','IdentifyNo','Account','Date','sothe','cardid');
 $i=0;
 $j=0;
 //$q = 'select * from cards where conf = "1" and datec="'.$_GET['date'].'" and bank = "'.$_SESSION['branch'].'" order by id asc';
 if ($_POST['type'] == '4')
 {
  $q = 'select * from `cards` where `conf`="3" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and ((`reason` = "InvalidPicture") or (`reason` = "InvalidInfo"))and `userid` in (select `id` from `users` where `Country` = "'.$_SESSION['branch'].'") ORDER BY `cards`.`id` ASC';
 }
 elseif ($_POST['type'] == '5')
 {
  $q = 'select * from `cards` where `conf`="7" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and `reason` = "InvalidPicture_KSV" and `userid` in (select `id` from `users` where `Country` = "'.$_SESSION['branch'].'") ORDER BY `cards`.`id` ASC';
 }
 $r = mysql_query($q);
 //echo mysql_error();
 $pdf=new FPDF('l','mm','A4');
 $i = 0;
//for($i=0;$i<$date.length;$i++){
    $pdf->AddPage();
 $pdf->SetFont('times','',10);
 //$pdf->Cell(35,4,'L?NH YÊU C?U IN TH?');
 $pdf->Cell(10,5,'STT');
 $pdf->Cell(25,5,'Ho ten KH');
 $pdf->Cell(35,5,'So CMND');
    $pdf->Cell(36,5,'So Tai khoan');
 $pdf->Cell(37,5,'So the');
 $pdf->Cell(38,5,'So tham chieu anh thiet ke');
 $pdf->Cell(39,5,'Ngay/gio');
 $pdf->Cell(43,5,'Ghi chu');
 //$pdf->Cell(45,5,'Ly do');
 while($w = mysql_fetch_array($r)){
 $i++;
 //echo ($w);
 $q2 = 'select * from users where id="'.$w['userId'].'"';
 $r2 = mysql_query($q2);
 $row2 = mysql_fetch_array($r2);
 
 $date = array($i,''.$row2['Salutation'].$row2['Firstname'].''.$row2['Lastname'].'',$row2['IdentifyNo'],$row2['account'],$w['dateC'],$w['sothe'],$w['id']);
 
 
 /*for($j=0;$j<2;$j++){
  $pdf->Cell(10,5,$header[$j].': '.$date[$j]);
  $pdf->Cell(40,5,$i[$j]);*/
        $pdf->Ln(7);
  $pdf->Cell(10,7,$i);
 
  $pdf->Cell(25,7,''.$row2['Salutation'].$row2['Firstname'].' '.$row2['Lastname'].'');
  $pdf->Cell(35,7,''.$row2['IdentifyNo'].'');
  $pdf->Cell(36,7,''.$row2['account'].'');
     $pdf->Cell(37,7,''.$w['sothe'].'');
  $pdf->Cell(38,7,''.$w['id'].'');
  $pdf->Cell(39,7,''.$w['dateC'].'');
  //$pdf->Cell(43,7,' ');
  //$pdf->Cell(45,7,''.$w['reasondetail'].'');
        $pdf->Ln(4);
 }
$pdf->Cell(10,11,'Date Printed:');
$pdf->Ln(4);
date_default_timezone_set('Bangkok, Hanoi, Jakarta');
putenv("Bangkok, Hanoi, Jakarta");
$pdf->Cell(10,15,gmdate("d/m/Y h:i A", time() + 7 * 3600));
$pdf->Ln(4);
/*$pdf->Cell(20,19,'Maker');
$pdf->Ln(4);
$pdf->Cell(41,19,'Checker');*/
$pdf->Output();
ob_end_flush();
?>

And I can't export to PDF:
Warning: Cannot modify header information - headers already sent by (output started at D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\rpt_invalid.php:1) in D:\CARDLIKEME_from 26_04_2010\admin\verification_branch\pdf\fpdf.php on line 1018
FPDF error: Some data has already been output, can't send PDF file
 
0
GremoryCommented:
Have you checked your file encoding type?

If you are using UTF8, you should use UTF8(without BOM).

With notepad++ you can make that simple conversion.
0
Shinesh PremrajanEngineering ManagerCommented:
First you had disabled the session in the top, but in the sql you are still referring the session variable.
Second if there is no session then you don't need the ob_start() and the ob_end_flush() functions.

Find the attached code

I had replaced the session for the branch with this value, put the appropriate value here, like i had placed a value 'india'

$branchval='india'

Hope this helps

<?php  
require('../verification_branch/pdf/fpdf.php');
include_once('../connect.php');  
//$header=array('Id','Name','IdentifyNo','Account','Date','sothe','cardid');
 $i=0;
$j=0;

$branchval='india';  //$_SESSION['branch'];

if ($_POST['type'] == '4')
{
 $q = 'select * from `cards` where `conf`="3" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and ((`reason` = "InvalidPicture") or (`reason` = "InvalidInfo"))and `userid` in (select `id` from `users` where `Country` = "'.$branchval.'") ORDER BY `cards`.`id` ASC';
}
elseif ($_POST['type'] == '5')
{
 $q = 'select * from `cards` where `conf`="7" and `dateC` >= "'.$_POST['Datefrom'].'" and `dateC` <= "'.$_POST['Dateto'].'" and `reason` = "InvalidPicture_KSV" and `userid` in (select `id` from `users` where `Country` = "'.$branchval.'") ORDER BY `cards`.`id` ASC';
}
 $r = mysql_query($q);
//echo mysql_error();
 $pdf=new FPDF('l','mm','A4');
$i = 0;
//for($i=0;$i<$date.length;$i++){
    $pdf->AddPage();
$pdf->SetFont('times','',10);
//$pdf->Cell(35,4,'L?NH YÊU C?U IN TH?');
$pdf->Cell(10,5,'STT');
$pdf->Cell(25,5,'Ho ten KH');
$pdf->Cell(35,5,'So CMND');
   $pdf->Cell(36,5,'So Tai khoan');
$pdf->Cell(37,5,'So the');
$pdf->Cell(38,5,'So tham chieu anh thiet ke');
$pdf->Cell(39,5,'Ngay/gio');
 $pdf->Cell(43,5,'Ghi chu');
 //$pdf->Cell(45,5,'Ly do');
 while($w = mysql_fetch_array($r)){
$i++;
//echo ($w);
$q2 = 'select * from users where id="'.$w['userId'].'"';
$r2 = mysql_query($q2);
$row2 = mysql_fetch_array($r2);

 $date = array($i,''.$row2['Salutation'].$row2['Firstname'].''.$row2['Lastname'].'',$row2['IdentifyNo'],$row2['account'],$w['dateC'],$w['sothe'],$w['id']);

 
/*for($j=0;$j<2;$j++){
 $pdf->Cell(10,5,$header[$j].': '.$date[$j]);
 $pdf->Cell(40,5,$i[$j]);*/
       $pdf->Ln(7);
 $pdf->Cell(10,7,$i);

  $pdf->Cell(25,7,''.$row2['Salutation'].$row2['Firstname'].' '.$row2['Lastname'].'');
 $pdf->Cell(35,7,''.$row2['IdentifyNo'].'');
 $pdf->Cell(36,7,''.$row2['account'].'');
    $pdf->Cell(37,7,''.$w['sothe'].'');
 $pdf->Cell(38,7,''.$w['id'].'');
 $pdf->Cell(39,7,''.$w['dateC'].'');
 //$pdf->Cell(43,7,' ');
 //$pdf->Cell(45,7,''.$w['reasondetail'].'');
       $pdf->Ln(4);
}
$pdf->Cell(10,11,'Date Printed:');
$pdf->Ln(4);
date_default_timezone_set('Bangkok, Hanoi, Jakarta');
putenv("Bangkok, Hanoi, Jakarta");
$pdf->Cell(10,15,gmdate("d/m/Y h:i A", time() + 7 * 3600));
$pdf->Ln(4);
/*$pdf->Cell(20,19,'Maker');
$pdf->Ln(4);
$pdf->Cell(41,19,'Checker');*/
$pdf->Output();
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dinhchung82Author Commented:
Tks for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.