更新记录:如何检查新文件是否已上传PHP

I am learning PHP, so forgive me if my question is somewhat silly.

I have created a form to update records in my db, which includes changing your name, age and image. When I update a record without changing the image it deletes the image (base64 string) from the updated row.

How can I check if an image has been changed or not, and if not: keep the present one unchanged or put into other words, not update that specific field. here is my php script for the update:

if( !is_null( $db ) && array_key_exists( 'edit_person', $_POST ) ):
  $pn = filter_var( trim( $_POST['name'] ), FILTER_SANITIZE_STRING );
  $n = filter_var( trim($_POST['age'] ), FILTER_SANITIZE_STRING );
  // check if another image has been uploaded
  $img = filter_var( trim($_POST['img'] ), FILTER_SANITIZE_STRING );
  // if not: don't update img
  $id = filter_var( trim ( $_POST['id'] ), FILTER_SANITIZE_NUMBER_INT );
  update_person( $db, $id, $img, $n, $pn ); 
 endif;

the update_person function:

   function update_person( &$db, $id, $img, $age, $name ){ 
   if( is_null( $db ) ) return '';
   $sql = "
    UPDATE
      xxx
    SET
      xxx.name = :name,
      xxx.age = :age,
      xxx.img = :img
    WHERE
      xxx.id = :id
    ";
  $vraag = $db->prepare( $sql );
  $vraag->bindValue( ':name', $name, PDO::PARAM_STR );
  $vraag->bindValue( ':age', $age, PDO::PARAM_STR );
  $vraag->bindValue( ':img', $img, PDO::PARAM_STR ); 
  $vraag->bindValue( ':id', $id, PDO::PARAM_INT );
  $vraag->execute();
}

Any help is very much appreciated!

Try the below code. If the $img variable is not set, do not update the image column in table

if( !is_null( $db ) && array_key_exists( 'edit_person', $_POST ) ):
  $pn = filter_var( trim( $_POST['name'] ), FILTER_SANITIZE_STRING );
  $n = filter_var( trim($_POST['age'] ), FILTER_SANITIZE_STRING );
  // check if another image has been uploaded
  $img = filter_var( trim($_POST['img'] ), FILTER_SANITIZE_STRING );
  // if not: don't update img      
  $id = filter_var( trim ( $_POST['id'] ), FILTER_SANITIZE_NUMBER_INT );

  if(!empty($img) && $img != '') :
    update_person( $db, $id, $n, $pn ); 
  else:
    update_person( $db, $id, $img, $n, $pn ); 
  endif;
endif;

Hope this helps.