Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to access $_POST variable in PHP if statement
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload