And the comments and solutions are:
- In lines 2 and 3 there is no need to send the header. FPDF will take care of all.
- Before line 11 you should use a
SetFont()
FPDF method to set the font you wish to use - On lines 24 and 25 you used mysql_query function twice, with errors in syntax
- On line 28 you used a nonexisting index 1 (only index 0 exists)
- Before line 30 you should again use
SetFont()
FPDF method (I think) - I do not know where the values
$row['id']
and$row['name']
come from. I ignored them. Make sure they exist. (credits also to pzuurveen) - Make sure you can write to the current directory or add a parameter to the
Output()
method (like'D'
for Download) - I do not know what is the point of line 30. Get rid of it. (credits also to pzuurveen)
The code that works for me is (a bit rearranged to be more clear):
<?php
$link=mysql_connect('localhost:3306','root','');
mysql_select_db('uploadimage');-
$query = "SELECT name FROM image1 WHERE id=1";
$result = mysql_query($query);
$row=mysql_fetch_row($result);
$name=$row[0];
require("fpdf.php");
class PDF1 extends FPDF
{
// Page header
function Header()
{
// Logo
$this->SetFont('Arial','B',12);
$this->Cell(0,10,'APPLICATION FORM FOR ADMISSION INTO MEDICAL PG DEGREE/DIPLOMA COURSES',0,0,'C');
$this->Ln(6);
$this->Cell(0,10,'UNDER MANAGEMENT QUOTA FOR THE ACADEMIC YEAR 2014-2015',0,0,'C');
$this->Ln(6);
$this->Cell(0,10,'-----',0,'C');
// Line break
$this->Ln(15);
}
}
$pdf = new PDF1();
$pdf->AddPage();
$pdf->SetFont('Arial','',16);
$pdf->Image($name);
// $pdf->Cell(0,10,'id'.$row['id'],0,1);
// $pdf->Cell(0,10,'name'.$row['name'],0,1);
$pdf->Cell(0,10,'id',0,1);
$pdf->Cell(0,10,'name',0,1);
$pdf->Output("image.pdf", 'D');
?>
The code works provided that the image is present and the path to it is correct.