Passing php variable as hidden input where html is contained in one echo -


i'm new php , still learning.

<?php if(isset($_post['btnlogin'])){     $myvariable = $_post['fieldparameter'];      if(condition){         //do     }else{        echo "           <form method='post' action='submit.php'><br/>                  <input type='hidden' name='myvariable' value='<?php echo $myvariable; ?>'/>           <br/>           <input type='submit' name='btnsubmit' id='submit' value='submit'>         </form>            ";         } } ?> 

notice variable $myvariable contained in main if block. i'm trying send value of $myvariable submit.php hidden field.

also, enclosed html tags using 1 echo statement double quotes.

i found related questions here in so can't find similar embedding php within long echo of html tags

i tried put value='<?php echo $studentno; ?>' no success.

i want access in submit.php file this,

submit.php

<?php      $avariable = $_post['myvariable'];     echo $avariable; ?> 

how can pass value contained in $myvariable hidden field? there wrong way use double , single quotes?

thank you.

you need type $myvariable instead of in string. double quotes "" creates string literal. doesn't directly output data inline html. can see syntax coloring in stackoverflow,

you can try these variants (simplified):

// code before echo "<input type='hidden' name='myvariable' value='$myvariable'/>"; // code after  // or //  // code before ?> <input type='hidden' name='myvariable' value='<?= $myvariable ?>'/> <?php // code after 

note quotes use in html don't affect php, long escape them (use \" , \' appropriate).

see html output web server more information.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -