I have two PHP script, and it seems the second script is not handling the $_POST
correctly.
a.php
Important part:
echo "<form action='b.php' method='post'>";
echo "<input type='submit' name='add' value='Add new items'>";
echo "</form>";
b.php
Important parts:
$error_variable1="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["something1"])) {
$error_variable1="not correct";
}
}
echo '<form action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'" method="post">';
echo '<textarea name="something1" rows="1" cols="10"></textarea>';
echo $error_variable1;
echo '<input type="submit" name="evaluate" value="Checking inputs">';
echo " </form>";
Unfortunately even at the first start of b.php it displays / gives value to $error_variable1 as "not correct."
But why is it working like this ? The user hasn't pressed the submit button yet. I want to give a "not correct" value for this variable when the "evaluate" submit button pressed.
Edit:
I am suspicious about that probably the POST (submit) from a.php is messing my b.php. What I would like is to display a text form with a submit button. When submit button has pressed ($POST) and the textarea is empty, then I want to show an error message to the user (not correct) and display the form again.