Search code examples
phphtmlparameter-passinghidden-field

passing value in hidden field from one page to another in php


I have a simple registration form. I want to pass value entered in one page to other in a text field. how to pass and access it from next page in php.

this is my first php page.

Thanks in advance.


Solution

  • You can add hidden fields within HTML and access them in PHP:

    <input type="hidden" name="myFieldName" value="someValue"/>
    

    Then in PHP:

    $val = $_POST['myFieldName'];
    

    If you're going to ouput this again you should use htmlspecialchars or something similar to prevent injection attacks.

    <input type="hidden" name="myFieldName" value="<?=htmlspecialchars($_POST['myFieldName']);?>"/>