0
 $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

mike
  • 21
  • 5
  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Progman May 19 '18 at 14:37

1 Answers1

1

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);
Chris
  • 4,672
  • 13
  • 52
  • 93