Not able to access $_POST variable in PHP if statement
<p>I am passing a hidden variable from HTML to a PHP page. In the PHP page I want to use that variable in my form.</p>

<pre><code>&lt;?php               
   $newVar=trim($_POST['newVar']);
   $subject = "new var is ---&gt; $newVar";
?&gt;
</code></pre>

<p>I am not able to use <code>$newVar</code> in any <code>if</code> statement - it shows blank. If I try to echo <code>$subject</code>, it shows the value of <code>$newVar</code> but when I try to echo the value of <code>$subject</code> in any <code>if</code> statement it does not show me the value of <code>$newVar</code>.</p>

<p><strong>My Code is:</strong>
html markup is:</p>

<pre><code>&lt;a href="#" class="applyNow"  onclick="document.sendVar.newVar.value='myVar'; document.sendVar.submit(); return false"&gt;New Variable&lt;/a&gt;

&lt;form method="post" name="sendVar" action="test.php" style="display:none;"&gt;
    &lt;input type="hidden" name="newVar" value=""&gt;
    &lt;input type="submit" value="Send form!"&gt;
&lt;/form&gt;
</code></pre>

<p>php:</p>

<pre><code>&lt;?php               
   $newVar=trim($_POST['newVar']);
   $subject = "new var is ---&gt; $newVar";
?&gt;


if(isset($_POST['submit'])) {
    if(!isset($hasError)) {
       $from_add = "test@test.com";         
       $emailTo = 'shruti@example.com';                 
       $headers = "From: $from_add \r\n";
       $headers .= "Reply-To: $from_add \r\n";
       $headers .= "Return-Path: $from_add\r\n";
       $headers .= "X-Mailer: PHP \r\n";

       mail($emailTo, $subject, $headers);
 // HERE in $subject.. value of newVar is not displaying


       $emailSent = true;
     }

    $from_add = "do-not-reply@example.com";     
    $headers = "From: $from_add \r\n";
    $headers .= "Reply-To: $from_add \r\n";
    $headers .= "Return-Path: $from_add\r\n";
    $headers .= "X-Mailer: PHP \r\n";
}
?&gt;
</code></pre>
