title: If Statement in Foreach loop
body: <p>I have a php page that I'm trying to simplify and am running into some issues that I can't get through alone.  My form takes user data, posts to itself, validates that fields have been filled in, and then displays form contents/posts to a mysql database.</p>
  
  <p>The issue I am having is that instead of having 20 if()/elseif statements I wanted to load the variable names into an array, loop through that array, and if a variable wasn't populated in the form have it produce an error message.  Unfortunately my code will display the error message regardless of whether the field has a value in it or not.</p>
  
  <p>As an additional note, I can add the $ShippingCo to my form and echo it but the notice that it isn't completed still shows up.</p>
  
  <p>Also, if the script enters the if statement I'd like for it to stop executing the remainder of the page after the closing   I've tried exit; without success.</p>
  
  <p>Here is what I have:</p>
  
  <pre><code>&lt;?php
  
  $ShippingCo = $_POST['ShippingCo'];
  $ShipAcct = $_POST['ShipAcct'];
  $ShipService = $_POST['ShipService'];
  $FOB = $_POST['FOB'];
  $Terms = $_POST['Terms'];
  
  $ENote[] = '$Terms';
  $ENote[] = '$FOB';
  $ENote[] = '$ShippingCo';
  $ENote[] = '$ShipAcct';
  $ENote[] = '$ShipService';
  
  $Emessg[] = 'Shipping Terms';
  $Emessg[] = 'FOB Method';
  $Emessg[] = 'Shipping Company';
  $Emessg[] = 'Shipping Account';
  $Emessg[] = 'Shipping Service Type';
  
  
  foreach ($ENote as $a =&gt; $b) {
  
  if(!$$ENote[$a]){       //I intentionally put the '$$' in this line otherwise none of the messages show. . . with data in the variables or not.
  
  $error = "Error!  Please Add the $Emessg[$a]!";
  ?&gt;
  &lt;table width="800" align="center"&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt;
  
  &lt;h2&gt;Sales Order Entry Form&lt;/h2&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt;
  &lt;h3&gt;
  &lt;font color="red"&gt;
  &lt;?php
  echo "$error";
  ?&gt;
  &lt;/font&gt;
  &lt;/h3&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td align="center"&gt;
  Please press back to properly complete the form&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;?php
  }
  }
  ?&gt;
  </code></pre>
  
  <p>Thank you in advance.</p>