S
S
Senseich2018-04-03 03:01:51
PHP
Senseich, 2018-04-03 03:01:51

How can I reset the data when the page is refreshed?

Maybe I phrased the question a little wrong. And most likely there have already been a lot of these, but there is such a simple code, when I send it, a line with age appears above the input field, it is necessary that later when the page is updated it will not be there, i.e. did not send POST again, everything seems to be simple, but I tried header('Location: http://myphp/Lesson_2_9/');. But then it does not display the text at all, and if you paste it down, it gives an error. I can't think of something)

<?php

if (isset($_POST['age'])) {

  $age = htmlspecialchars($_POST['age']);


  if ($age > 30) {
    echo "Вам больше 30 лет";
  } 
  elseif ($age < 30) {
    echo "Вам меньше 30 лет";
  } 
  else echo "Вам 30 лет";

}


?>

<form action="" method="post">
  <input type="text" name="age" class="text">
  <input type="submit" value="Отправить">
</form>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2018-04-03
@Senseich

You can't display text and redirect at the same time. Pick one.
To save the text - it must be saved. To a database, to a file, to a session, or any other way you like.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question