title: Validation in PHP not being understood
body: <p>I am having difficulty understanding the PHP code below.</p>
  
  <p>The first line of the code is a superglobal variable with a request element in it:<br>
  I assume this line simply states which method was used to send data to the server, in this case POST was used.</p>
  
  <p>But what I am a little fuzzy about is the second line.<br>
  Do I understand correctly that this line means "<em>if no name is posted, then something happens</em>"?<br>
  That <em>something</em> seems to be the third line, or else the fourth line is activated.<br>
  This is where I get lost.</p>
  
  <p>The third line assigns a statement to the variable <code>$error</code>, and the fourth line assigns another statement to the variable <code>$name</code>.<br>
  But <code>$error</code> seems to have TWO different statements attached to it, and I am not clear as to what <code>$name = test_input($_POST["name"])</code> means.<br>
  In other words, only line number one is clear to me, and the line containing "<em>if NOT preg match</em>", because I'm familiar with preg match.</p>
  
  <p>BUT, what I am also not clear about is the line that comes after "if NOT preg match".<br>
  Does <code>$name = ""</code> mean that if you input anything other than letters or whitespace, then what you have just typed in will be deleted?</p>
  
  <p>And (again) I am confused about the fact that <code>$error</code> has <strong>two</strong> values associated with it.<br>
  Could someone please enlighten me?</p>
  
  <pre><code>if ($_SERVER["REQUEST_METHOD"] == "POST") {
      if (empty($_POST["name"])) {
          $error = "Name is required";
      } else {
          $name = test_input($_POST["name"]);
  
          if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
              $name = "";
              $error = "Anything that is not letters or whitespace are not allowed";
          }
      }
  }
  </code></pre>