Hmm! Method A or method B? When you are caught on the horns of a dilemma, look for a third way
Consider a sticky registration form. When first loaded the input values are blank, but if the validation fails you want to show the user's values. In this situation I like the "null coalesce" operator, ie "??".
Example
<?php
$fname = $_POST['fname'] ?? '';
$lname = $_POST['lname'] ?? '';
$email = $_POST['email'] ?? '';
$mobile = $_POST['mobile'] ?? '';
$error_message = '';
if ($_SERVER['REQUEST_METHOD']=='POST') {
$errors = []; // array for any error messages
// validate input here
if (!$errors) {
// update database here
header("location: thispage.php"); // reload page
exit;
}
else {
$error_message = 'yada yada';
}
}
?>
<html>
<body>
<form method='POST'>
First name : <input type='text' name='fname' value='<?=$fname?>'> <br>
Last name : <input type='text' name='lname' value='<?=$lname?>'> <br>
Email : <input type='text' name='email' value='<?=$email?>'> <br>
Mobile : <input type='text' name='mobile' value='<?=$mobile?>'> <br>
<br>
<button type='submit'>Submit</button>
</form>
<?=$error_message?>
</body>
</html>