-2

The code is given.. i want to generate a pdf with content,what i entered in the text field

<form method= 'post' action =''>

Name<input type="text" name="name">

<input type="submit" value="submit" name="submit">

</form>

<?php

require("fpdf.php");

$pdf = new FPDF();

$pdf->AddPage();

$pdf->SetFont('Arial','B',16);

$a=$_POST["add"];

$pdf->Cell(40,10,$a);

$pdf->Output();

?>

but the result is...

FPDF error: Some data has already been output, can't send PDF file Somebody plz help

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
Amit
  • 219
  • 2
  • 7

1 Answers1

0

Output your form only if the form has not been submitted:

<?php
if( !isset($_POST['submit']) ) {
?>
    <form method='post' action=''>Name
        <input type="text" name="name" />
        <input type="submit" value="submit" name="submit" />
    </form>
<?php
}
else {
    require("fpdf.php");
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $a=$_POST["add"];
    $pdf->Cell(40,10,$a);
    $pdf->Output();
}
?>
hjpotter92
  • 78,589
  • 36
  • 144
  • 183