POST method does not work!

1

Well, I'm making a simple code ... I just want to get the information typed in the form. But it's not right, GET works ... the Post does not.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <form action="index.php" method="POST">
        Nome: <input type="text" name="nome" value="1">
        Idade: <input type="text" name="idade" />
        <input type="submit" value="POST"/>
    </form>
    <?php

    $nome = $_POST["nome"];
    echo $nome;
    ?>
</body>
</html>

I have tried to do it in a separate file, but it did not work, is it something in php.ini? I'm using XAMP tbm ...

    
asked by anonymous 09.12.2017 / 04:46

3 answers

1

Use this form below and submit the form and see if it will make a mistake. Here at home it worked good ...

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <form action="#" method="POST">
            Nome: <input type="text" name="nome" value="1">
            Idade: <input type="text" name="idade" />
            <input type="submit" value="POST"/>
        </form>
        <pre>
            <?php
            // Habilitar a exibição de erros em tempo de execução.
            ini_set("display_errors", "on");
            // Depurar a super global POST.
            print_r($_POST);
            // Testar a tipagem da super global POST.
            var_dump($_POST);
            ?>
        </pre>

    </body>
</html>
<?php
$nome = $_POST["nome"];
$idade = $_POST["idade"];
echo "Olá $nome, você tem $idade ano(s)... legal!!!";
?>

The Return will be:

  

Array (       [name] = > 1       [age] = > 33) array (2) {["name"] = > string (1) "1" ["age"] = > string (2) "33"}            Hello 1, you have 33 year (s) ... cool !!!

    
28.09.2018 / 01:37
0

Locate in your php.ini the enable_post_data_reading line. Change to on :

enable_post_data_reading = on

PHP Documentation :

  

Disabling this option causes $ _POST and $ _FILES not to be   completed. The only way to read data posted will be through the   stream wrapper php: // input. This may be useful for brokering   requests, or to process POST data in an efficient manner in   terms of allocated memory.

    
09.12.2017 / 05:20
-3

Hello,

If you are inserting PHP on the same form page, you should change your form's action:

DE:

<form action="index.php" method="POST">

TO:

<form action="<?=($_SERVER['PHP_SELF'])?>" method="POST">
    
09.12.2017 / 13:58