title: Notice: Undefined Variable - form processing?
body: <p>I created a sample form and code below to illustrate. I know i can turn notices off in php but would rather fix the problem rather than ignore it.</p>
  
  <p>When i create forms i do like what i have posted below, obviously this is just a sample with no sanitization etc. </p>
  
  <p>I sort of know why i get the <strong>Notice: Undefined Variable</strong> which i know sounds dumb but not sure what's the easiest and correct way to solve it.</p>
  
  <p>Could one of you great people out there show me how to stop this notice appearing? </p>
  
  <p>It's only now i realised i did not have all error reporting on in WAMP and i have created allot of forms and i really don't want to be doing loads of re-editing code to fix it, hence i'm looking for a good, simple solution to solve it so i can go into all my forms and sort it once and for all.</p>
  
  <pre><code>&lt;?php
  // check if form has been submitted
  if(isset($_POST['submit'])){
  
      // fetch form data
      $name = $_POST['name']; 
      $username = $_POST['username']; 
      $email = $_POST['email'];
  
      // check form fields
      if(empty($name)){
          $error .= 'Enter name &lt;br /&gt;';
      }
      if(empty($username)){
          $error .= 'Enter username &lt;br /&gt;';
      }
      if(empty($email)){
          $error .= 'Enter email &lt;br /&gt;';
      }
  
      // check if errors exist
      if(isset($error)){
          echo $error;    
      } else {
          // process form as normal   
      }
  }
  ?&gt;
  
  &lt;form method="post" action="&lt;?php $_SERVER['PHP_SELF']; ?&gt;"&gt;
  
  &lt;label for="name"&gt;Name:&lt;/label&gt;
  &lt;input type="text" name="name" value="&lt;?php if(isset($name)) echo $name; ?&gt;" /&gt;
  
  &lt;label for="name"&gt;Username:&lt;/label&gt;
  &lt;input type="text" name="username" value="&lt;?php if(isset($username)) echo $username; ?&gt;" /&gt;
  
  &lt;label for="email"&gt;Email:&lt;/label&gt;
  &lt;input type="text" name="email" value="&lt;?php if(isset($email)) echo $email; ?&gt;" /&gt;
  
  &lt;input type="submit" name="submit" value="Send" /&gt;
  
  &lt;/form&gt;
  </code></pre>