 <p>For the $_POST variables use syntax as $_POST['your variable name']</p> <p>I corrected your code as below:</p> <pre><code>&lt;form action="test.php" method="post"&gt; First Name: &lt;input type="text" name="fname"&gt;&lt;br&gt; Last Name: &lt;input type="text" name="lname"&gt;&lt;br&gt; E-mail: &lt;input type="text" name="email"&gt;&lt;br&gt; &lt;input type="hidden" name="submitted" value="1"&gt; &lt;input type="submit"&gt; &lt;/form&gt; &lt;?php //If form was submitted if ($_POST['submitted']==1) { $errormsg = ""; //Initialize errors if ($_POST['fname']){ $fname = $_POST['fname']; //If fname was entered } else{ $errormsg = "Please enter first name"; } if ($_POST['lname']){ $lname = $_POST['lname']; //If lname was entered } else{ if ($errormsg){ //If there is already an error, add next error $errormsg = $errormsg . ", last name"; } else{ $errormsg = "Please enter last name"; } } if ($_POST['email']){ $email = $_POST['email']; //If email was entered } else{ if ($errormsg){ //If there is already an error, add next error $errormsg = $errormsg . " &amp; email"; }else{ $errormsg = "Please enter email"; } } } if ($errormsg){ //If any errors display them echo "&lt;div class=\"box red\"&gt;$errormsg&lt;/div&gt;"; } //If all fields present if ($fname &amp;&amp; $lname &amp;&amp; $email){ //Do something echo "&lt;div class=\"box green\"&gt;Form completed!&lt;/div&gt;"; } ?&gt; </code></pre>