Lukas Lukas - 1 year ago 36
HTML Question

PHP Errors aren't showing

I have a simple

HTML script

<form action="" method="post">
<input type="text" name="amount">
<?php echo $amountError; ?>
<input type="submit">

And I display errors using this:

$amount = $_POST['amount'];

if (empty($_POST['amount'])) {
$amountError = 'Empty amount';
} else {
header("Location: apmoketi.php");

In the
file there is only one line
echo $amount = $_POST['amount'];

However, when I'm trying to display data in the
page, I don't get the value of the
variable using
, but using
I can get it but my
code doesn't checking for any errors, why?


A call to header("Location: apmoketi.php"); makes the browser follow the specified URL as another, completely separate request. This new request doesn't have access to the POST data of the previous one.

Your options:

  1. use include so apmoketi.php has access to the variables of the current script
  2. use sessions to preserve data between requests
  3. use a query parameter to carry the value over:

    header('Location: apmoketi.php?amount=' . urlencode($amount));