I am trying to display the output of either the password or mobile invalid statement to a HTML Page. Here is my code:
<?php
  session_start();
  if(isset($_POST['register'])) {
    $phone = ($_POST['tphone']);
    $upass = ($_POST['tpassword']);     
    if (!@preg_match('/^(?=.*\d{3,})(?=.*[A-Za-z]{5,})[0-9A-Za-z!@#$%]{8,32}$/', $upass)) {
      $upass = 'You have enter an invalid password';
    } 
    else if ( !@ereg( "^[0-9]{3}-[0-9]{7}$", $phone)) {
      $mobile = 'Invalid mobile'
    }
  }
?>
<html>
  <body>
    <p><?php echo $upass ?>.</p>
    <form method="post">
      <input type="text" name="tphone" placeholder="First Name" class="form-name"  required>
      <input type="password" name="tpassword" placeholder="Last Name" class="form-name2" required>
      <button type="submit" name = "register" class="btn-register">Register</button>  
    </form>
  </body>
</html>
The problem here is how should I use the PHP variable in my HTML like I have defined $upass inside the p tags. I also want to set this variable when the register button is clicked.
Right now when I echo $upass, it displays Undefined variable when I have not selected the register button.
 
     
     
    