$name = "";
$email= "";
$errMsg = array(
$err = false;

if i write the above code outside the if(isset($_POST['Submit'])) then i am able to get values on the page.

$errMsg["name"] = "Name is required";
<?php echo htmlspecialchars($name);?>

why not i have directly access to these errors,,,, as form is on the same page


if (empty($_POST["name"])){
$errMsg["name"] = "Name is required";
$err= True;
// check e-mail */

if (empty($_POST["email"])){
$errMsg["email"] = "Email is required";
$err = True;

<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<label for="name">Your name:</label>
<input type="text" name="name" class="form-control" id="userName" value="<?php echo htmlspecialchars($name);?>" />
<span class="error"><?php echo $errMsg["name"];?></span>

<label for="email">Your email:</label>
<input type="text" name ="email" id="userEmail" class="form-control" value="<?php echo htmlspecialchars($email);?>" />
<span class="error"><?php echo $errMsg["email"];?></span>