$post

Hello.

I need :

  1. Get $POST value
  2. Assign it to variable
  3. Request another $POST
  4. Refer to previous $POST value.

Does it possible?

For example :

2 forms

echo '<form action="index.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="fage" />
<input type="submit" />
</form>';


echo '<form action="index.php" method="post">
Name: <input type="text" name="lname" />
Level: <input type="text" name="lage" />
<input type="submit" />
</form>';


Assign to variables like you said

$fname = filter_input(INPUT_POST, 'fname', FILTER_SANITIZE_STRING);
$age = filter_input(INPUT_POST, 'fage', FILTER_SANITIZE_STRING);
$name = filter_input(INPUT_POST, 'lname', FILTER_SANITIZE_STRING);
$level = filter_input(INPUT_POST, 'lage', FILTER_SANITIZE_STRING);

Then echo it

echo "\\$_POST['fname'] = $fname";
echo '<br /><br />';
echo "\\$_POST['age'] = $age";
echo "<p style='color:green; font-weight: bold'>***********************</p>";
echo "\\$_POST['lname'] = $name";
echo '<br /><br />';
echo "\\$_POST['lage'] = $level";

But When I submit first form , second is getting erased.
Any way to keep $_POST value from first form after submiting another one?

Thanks , that’s helped.

Using filter_input does all of the above, and is the recommended way these days as you can specify [url=“http://www.php.net/manual/en/filter.filters.php”]types of filters to use, to specify sanitisation and validation requirements.


$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);

Yes, store anything you want to persist across multiple pages in the session


session_start(); // must be called before any output to browser
$_SESSION['whatever'] = ['something']; // $_SESSION['whatever'] will keep it's value till session times out

Do you mean $_POST?

// 1. Get $POST value
// 2. Assign it to variable


  $value_001 = isset($_POST['value_001']) ? $_POST['value_001'] : 'EMPTY AND/OR NOT SET';

// 3. Request another $POST
// 4. Refer to previous $POST value.

Take a look at: http://www.w3schools.com/php/php_forms.asp

and:
http://www.w3schools.com/php/php_post.asp

.