I'm trying to make a concept sign up page in PHP, and I need to require the user to enter in text for ALL inputs. If not, it would say for example, "You need a valid email address!" or something like that.
My problem is getting the text to actually show. When I submit, it doesn't show the error, it rather just stays with a star.
My code:
<html>
  <head>
    <link rel="stylesheet" href="style.css">
    <title>Test</title>
  </head>
  <body>
    <?php
      $emailErr = $usernameErr = $passwordErr = "";
      $email = $username = $password = "";
      if ($_SERVER["REQUIRED_METHOD"] == "POST") {
        if (empty($_POST["email"])) {
          $emailErr = "You must enter a valid email address!";
        } else {
          $email = testData($_POST["email"]);
        }
        if (empty($_POST["username"])) {
          $usernameErr = "You must create a username!";
        } else {
          $username = testData($_POST["username"]);
        }
        if (empty($_POST["password"])) {
          $passwordErr = "You must create a password!";
        } else {
          $password = testData($_POST["password"]);
        }
      }
      function testData($data) {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
      }
    ?>
    <p><span class="error">* Required Field(s)</span></p>
    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
      <label for="email">Email Address:</label>
      <span class="error">* <?php echo $emailErr;?></span>
      <br>
      <input type="email" name="email" placeholder="someone@organization.com" />
      <br><br>
      <label for="username">Username:</label>
      <span class="error">* <?php echo $usernameErr;?></span>
      <br>
      <input type="text" name="username" />
      <br><br>
      <label for="password">Password:</label>
      <span class="error">* <?php echo $passwordErr;?></span>
      <br>
      <input type="password" name="password" />
      <br><br>
      <input type="submit" value="Create Account!">
    </form>
  </body>
</html>
Can anyone please help me find out a solution to my situation?
 
     
     
     
    