mike
mike

Reputation: 21

Undefined variable: pdf in FPDF

 $query = mysqli_query($con,"select * from s_users
        where
        s_id = '".$_GET['s_id']."'");   
    $row = mysqli_fetch_array($query);
    if ($row['status'] == 1) { //1 
    $pdf = new PDF_Code128('P','mm','A4');
    $pdf->AddPage();
    $pdf->Cell(190  ,220,'',1,0);
     $pdf->image('images/logo.png', 14, 16, -200);
    $pdf->image($row['imgdata'], 163, 16, -210);
    $pdf->SetFont('Arial','B',14);
    } else {
    $pdf->image('images/profiledefault.jpg', 163, 16, -210);
    }

this is my code for displaying profile picture using FPDF,i want to have a default picture display when there is no profile picture. am using an IFELSE statement, but i get undefined variable pdf in the else statement

Upvotes: 0

Views: 1600

Answers (1)

Chris
Chris

Reputation: 4748

Your issue is with the if statement. If status=1 then you're defining $pdf. If this isn't the case then you don't.

You should re-jig your code along these lines ...

$query = mysqli_query($con,"select * from s_users where s_id = '".$_GET['s_id']."'");   
$row = mysqli_fetch_array($query);

$pdf = new PDF_Code128('P','mm','A4');
$pdf->AddPage();
$pdf->Cell(190  ,220,'',1,0);

if ($row['status'] == 1) { //1 
    $pdf->image('images/logo.png', 14, 16, -200);
    $pdf->image($row['imgdata'], 163, 16, -210);
} else {
    $pdf->image('images/profiledefault.jpg', 163, 16, -210);
}

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

Upvotes: 1

Related Questions