Nothing happens when I send in php form

2

I am studying php and I am doing a form where it is very basic that contains 2 input (Number 1 and Number 2) and a send button, what happens is that when you write the values in the input and give the send nothing happens, the only thing that does is refresh the page, here the code

<body>
<form action="formularios.php" method="post">
    <label>Numero 1 <input type="text" name="numero1" value="" id="numero1"></label>
    <label>Numero 2<input type="text" name="numero2" value="" id="numero2"></label>
    <button type="submit" id="button" value="Enviar">Enviar</button>
</form>
<?php 
if (isset($_POST["button"])){
    $num1=$_POST["numero1"];
    $num2=$_POST["numero2"];

    $suma= $num1+$num2;
    echo "La suma es: " . $suma;
}

 ?>

    
asked by Victor Escalona 29.03.2018 в 00:56
source

1 answer

3

$_POST works with the tags name of the HTML elements, that's why you're not entering here:

if (isset($_POST["button"])){

because in your HTML there is no element whose name is button .

If you change the button like this:

<button type="submit" name="button" value="Enviar">Enviar</button>

should work.

Strangely this is not mentioned in the explanation of $_POST in the PHP Manual . It appears just in a user comment , made just one year ago.

    
answered by 29.03.2018 / 01:00
source