1

This is my code:

<?php
include ("../connections.php");
require("fpdf181/fpdf.php");
ob_end_clean();
ob_start();
if (isset($_POST["btn_1"])) {
class PDF extends FPDF{

function Header(){
  global $title;
  $w = $this->GetStringWidth($title)+6;
  $this->SetX((210-$w)/2);
  $this->Image('fpdf181/logo.png',10,6,20);
  $this->SetFont('Times','B',30);
  $this->SetLineWidth(1);
  $this->Cell($w,10,$title,0,0,'C');
  $this->Ln(20);
}
function table(){

}
function layout(){


}

function footer(){
  $this->SetY(-15);
  $this->SetFont('Arial','I',8);
  $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
}
}
$pdf = new PDF();
$title = "MONTHLY SALES REPORT";
$pdf->SetTitle($title);
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$pdf->SetFillColor(180,180,255);
$pdf->SetDrawColor(50,50,100);
$pdf->Cell(10,10,"Generic Name",1,0,'',true);
$pdf->Cell(60,10,'Branded Name',1,0,'',true);
$pdf->Cell(60,10,'Unit',1,0,'',true);
$pdf->Cell(65,10,'QTY Available',1,0,'',true);
$pdf->Ln();
$view_query = mysqli_query($connections, "SELECT * FROM product");
while ($row = mysqli_fetch_assoc($view_query))
{

$db_genericname = $row["genericname"];
$db_brandedname = $row["brandedname"];
$db_unit = $row["unit"];
$db_quantityavailable = $row["quantity_available"];

$pdf->Cell(10,10,$db_genericname,1);
$pdf->Cell(60,10,$db_brandedname,1); 
$pdf->Cell(60,10,$db_unit,1); 
$pdf->Cell(65,10,$db_quantityavailable,1); 
$pdf->Ln();
}
$pdf->Output();
ob_end_flush();
}
?>

This is the error i get:

Fatal error: Uncaught Exception: FPDF error: Some data has already been output, can't send PDF file (output started at C:\xampp\htdocs\SAD\manager\productrecords.php:1) in C:\xampp\htdocs\SAD\manager\fpdf181\fpdf.php:271 Stack trace: #0 C:\xampp\htdocs\SAD\manager\fpdf181\fpdf.php(1052): FPDF->Error('Some data has a...') #1 C:\xampp\htdocs\SAD\manager\fpdf181\fpdf.php(999): FPDF->_checkoutput() #2 C:\xampp\htdocs\SAD\manager\productrecords.php(258): FPDF->Output() #3 {main} thrown in C:\xampp\htdocs\SAD\manager\fpdf181\fpdf.php on line 271

I do know what to do anymore i tried my best searching solutions for this and tried them but to no good. A little help would be appreciated :)

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
Brix
  • 29
  • 1
  • 8
  • This typically is the result of _accidental_ output. Maybe white spaces after a closing php tag (I see you use those at the end of files, _don't_). – arkascha Mar 15 '18 at 14:48
  • try not to output any data before the pdf->output() – Masivuye Cokile Mar 15 '18 at 14:48
  • 1
    Possible duplicate of [FPDF error: Some data has already been output, can't send PDF](https://stackoverflow.com/questions/9475686/fpdf-error-some-data-has-already-been-output-cant-send-pdf) – CBroe Mar 15 '18 at 14:55
  • i checked that white space too i backspaced that part so many times to make sure hehe. and what do you mean dont output anything? sorry i am still new to PHP just started learning this – Brix Mar 15 '18 at 14:55
  • The error message already mentions where the output started, so go check there. – CBroe Mar 15 '18 at 14:56
  • i went to that question too and tried the suggestions there and still says the same error – Brix Mar 15 '18 at 14:57

0 Answers0