jarvis
jarvis

Reputation: 11

Fpdf goes to header Location without generating Pdf.

The page automatically redirects to entry.php without generating the pdf. I want it to generate the pdf and then redirect. When the header(Location: entry.php); is removed, it generates Pdf. Is there any other way to achieve it?

include('connection.php');  
ob_start ();  
require('fpdf/fpdf.php');  


if ($_SERVER['REQUEST_METHOD'] == 'POST')  
{
    //collect form data
    $name = $_POST['fname'];  
   $lname = $_POST['lname'];  
    $email = $_POST['email'];  
    $gender=$_POST['dropdown1'];  
    $age=$_POST['age'];  
    $qualification=$_POST['qualification'];  
    $fees=$_POST['fee'];  
    $discount=$_POST['discount'];  
    $tobepaid=$_POST['tobepaid'];  
    $paystatus=$_POST['dropdown2'];  


    $query = "SELECT * FROM details WHERE email = '$email'";  
$result = mysqli_query($conn, $query) or die (mysqli_error($conn));  

if (mysqli_num_rows($result) > 0) {  
    session_start();  
    $_SESSION['registered'] = "Record Already exists.";  
    mysqli_close($conn);  
    header('Location: entry.php');  
    exit();  


}  
    else  


$sql = "INSERT INTO details(FirstName, LastName, Email, Sex, Age, Qualification, Fees, Discount, Tobepaid, Paystatus)
 VALUES ('$name', '$lname', '$email', '$gender', '$age', '$qualification', '$fees', '$discount', '$tobepaid', '$paystatus')";  

$result = mysqli_query($conn, $sql);  


    if( !mysqli_fetch_assoc ($result ))  
{
$_SESSION['Msg']= "Submitted Successfully";  


            class PDF extends FPDF
{
// Page header
function Header()  
{


    // Arial bold 15
    $this->SetFont('Arial','B',15);
    // Move to the right
    $this->Cell(80);
    // Title
    $this->Cell(60,10,'Convert HTML TO PDF',1,0,'C');
    // Line break
    $this->Ln(20);
}

// Page footer  
function Footer()  
{
    // Position at 1.5 cm from bottom  
    $this->SetY(-15);  
    // Arial italic 8  
    $this->SetFont('Arial','I',8);  
    // Page number  
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');  
}  
}  

// Instanciation of inherited class  
$pdf = new PDF();  
$pdf->AliasNbPages();  
$pdf->AddPage();  
$pdf->SetFont('Times','',12);  

$pdf->Cell(0,10,'Name : '.$_POST["lname"],0,1);  
$pdf->Cell(0,10,'Email : '.$_POST["email"],0,1);  
$pdf->Cell(0,10,'Mobile : '.$_POST["fname"],0,1);  
$pdf->Cell(0,10,'Comment : '.$_POST["age"],0,1);  

    $pdfname=$_SESSION['UserID'];  


$pdf->Output('Filename.pdf','D');  

    header("Location: entry.php");  
}  

else{
    $_SESSION['errMsg'] = "Invalid Details";
    header("Location: entry.php");

}   

Upvotes: 0

Views: 523

Answers (1)

user557846
user557846

Reputation:

http://fpdf.org/en/doc/output.htm

D: send to the browser and force a file download with the name given by name.

so your arpprach should be to use

F: save to a local file with the name given by name (may include a path).

Upvotes: 1

Related Questions