Vineet Kumar Saini

Vineet Kumar Saini

  • NA
  • 10.4k
  • 7.4m

Error in my php code !!

Sep 5 2012 9:14 AM
Hi Friends

Currently I'm working on a PHP project. I want to generate pdf on button click but when we click on button then i get an error "FPDF error: Some data has already been output, can't send PDF file".

My code are

<?php
/**
 * @version  1.0.0
 * @package  com_ram
 * @copyright  Copyright (C) 2012. All rights reserved.
 * @license  GNU General Public License version 2 or later; see LICENSE.txt
 * @author  vineet saini <[email protected]> - http://vineetsaini.wordpress.com
 */


// no direct access
defined('_JEXEC') or die;
?>

<?php if($this->items) : ?>

  <div class="items">

<?php

include('fpdf.php');

$pdf=new FPDF();

$pdf->SetAutoPageBreak(false);

$pdf->AddPage();

$y_axis_initial = 8;

$pdf->SetFillColor(232,232,232);

$pdf->SetY($y_axis_initial);
$pdf->SetX(80);

$pdf->SetFont('Arial','B',12);
$pdf->Cell(30,20,'Curriculum Vitae')."</br>";
$pdf->Ln(20);

$row_height = 6;

$y_axis=50;

$y_axis = $y_axis + $row_height;

$con=mysql_connect ("localhost","root","");
mysql_select_db ("pradeep_jo17",$con);
if(@$_POST ['sel'])
{

$result=mysql_query('select * from jos_resume');

//initialize counter
$i = 0;

//Set maximum rows per page
$max = 25;

while($row = mysql_fetch_array($result))
{
  //If the current row is the last one, create new page and print column title
  if ($i == $max)
  {
    $pdf->AddPage();

    //print column titles for the current page
    $pdf->SetY($y_axis_initial);
    $pdf->SetX(25);
 
    $y_axis = $y_axis + $row_height;
   
    //Set $i variable to 0 (first row)
    $i = 0;
  }


  $name = $row['fullname'];
  $address = $row['address'];
  $objective = $row['objective'];
  $profqualificatiion = $row['profqualification'];
  $acequalificatiion = $row['acequalification'];
  $workexp = $row['workexp'];
  $techskills = $row['techskills'];
  $hobbies = $row['hobbies'];
  $strength = $row['strength'];
  $achivements = $row['achivements'];
  $projectdetails = $row['projectdetails'];
  $personaldetails = $row['personaldetails'];
  $date = $row['date'];
  $signature = $row['signature'];
 
  //$pdf->SetY($y_axis);
  $pdf->SetX(10);
  //$pdf->Cell(20,6,$code,1,0,'L',1);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$name);
  $pdf->Ln(5);
  $pdf->Cell(20,6,$address);
  $pdf->Ln(8);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Career Objective');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$objective);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Professional Qualification');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$profqualificatiion);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Academic Qualification');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$acequalificatiion);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Working Experience');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$workexp);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Technical Skills');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$techskills);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Hobbies');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$hobbies);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Strength');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$strength);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Achievements');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$achivements);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Project Details');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$projectdetails);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Personal Details');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$personaldetails);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Date');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$date);
  $pdf->Ln(5);
  $pdf->SetFont('Arial','B',12);
  $pdf->Cell(30,20,'Signature');
  $pdf->Ln(12);
  $pdf->SetFont('Arial','I',12);
  $pdf->Cell(20,6,$signature);
 

  //Go to next row
  //$y_axis = $y_axis + $row_height;
  $i = $i + 1;
}
}
//Send file
$pdf->Output();

?>
 
<form name="f" method="post" action="">
<table border="1"  bgcolor="#A9D8DE" align="center">
<caption><u><h2>Resume Form</h2></u></caption>
<tr><td height="30"><h4>Full Name</h4></td><td align="left"><input type="text" name="txt1"/></td></tr>
<tr><td height="30"><h4>Address</h4></td><td align="left"><input type="text" name="txt2"/></td></tr>
<tr><td height="30"><h4>Objective</h4></td><td align="left"><input type="text" name="txt3"/></td></tr>
<tr><td height="30"><h4>Professional Qualification</h4></td><td align="left"><input type="text" name="txt4"/></td></tr>
<tr><td height="30"><h4>Academic Qualification</h4></td><td align="left"><input type="text" name="txt5"/></td></tr>
<tr><td height="30"><h4>Working Experience</h4></td><td align="left"><input type="text" name="txt6"/></td></tr>
<tr><td height="30"><h4>Technical Skills</h4></td><td align="left"><input type="text" name="txt7"/></td></tr>
<tr><td height="30"><h4>Hobbies</h4></td><td align="left"><input type="text" name="txt8"/></td></tr>
<tr><td height="30"><h4>Strength</h4></td><td align="left"><input type="text" name="txt9"/></td></tr>
<tr><td height="30"><h4>Achievements</h4></td><td align="left"><input type="text" name="txt10"/></td></tr>
<tr><td height="30"><h4>Project Details</h4></td><td align="left"><input type="text" name="txt11"/></td></tr>
<tr><td height="30"><h4>Personal Details</h4></td><td align="left"><input type="text" name="txt12"/></td></tr>
<tr><td height="30"><h4>Date</h4><input type="text" name="txt13"></td><td align="left"><h4>Signature</h4><input type="text"  name="txt14"></td></tr>
<tr><td colspan="2" align="center"><h4><input type="submit" value="Submit" name="inser" /><input type="submit" name="sel" value="Generate PDF" /></h4></td></tr>

</table>
</form>
   
  </div>

  <div class="pagination">
  <p class="counter">
  <?php echo $this->pagination->getPagesCounter(); ?>
  </p>
  <?php echo $this->pagination->getPagesLinks(); ?>
  </div>


<?php endif; ?>

---------------------------------------------------------------------

Please resolve my problem anyone ? Please help me ?


Thanks.