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 :)