Data that was sent using the POST method is not passed to the script. Through the GET method everything works. Sample code.

<!DOCTYPE html> <html> <head> <title>Title</title> </head> <body> <form method="POST"> <input type="text" name="value"> <input type="submit" name="submit" value="Submit"> </form> </body> </html> <?php ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); if (isset ($_POST['submit'])) { if (isset ($_POST['value'])) { $n = $_POST['value']; function factorial($n) { if ($n <= 1 || $n == 1) { return 1; } else { return $n * factorial($n - 1); } } echo factorial($n) . "<br>"; function factLoop($n) { $result = 1; for ($i = 2; $i <= $n; $i++) { $result = $result * $i; } return $result; } echo factLoop($n); } else { echo "Введіть число"; } } print_r($_POST) ; 
  • How do you understand that does not work? It is currently working. What does Network say in developer tools? ... By the way, so that the inscription is displayed, enter the number you need to check the value for emptiness if (isset ($_POST['value']) && !empty($_POST['value'])) .... because if the post went, then value exists (unless of course there was a field with the same name on the form) - Alexey Shimansky
  • value: 10 submit: Submit - user3548331
  • Request URL: localhost: 63342 / sonicTrain / www / index.php Request Method: POST Status Code: 200 OK Remote Address: 127.0.0.1: 63342 - user3548331
  • value:10 submit:Submit .. data is transferred .... - Alexey Shimansky
  • Yes, the data is transferred, but print_r displays an empty array, and the functions do not work. - user3548331

1 answer 1

The whole problem was in PHPStorm. If you run the script from the IDE, it uses its server, and it does not transmit data using the POST method.