I need to do this: Create an HTML form with two text fields a div for presentation of the results and a submit button. 1 - Create a script in PHP, which receives form data and reports in the div element of the form the result of the sum of the numbers
I tried to do but it is giving error and I do not know how to solve it because I am a beginner in programming
HELP !!!!!
<body>
<div>
<form action="../model/numeros.php" method="POST">
Informe um número
<input type="text" placeholder="Número" name="n1"><br>
Informe outro número
<input type="text" placeholder="Número" name="n2"><br>
<input type="submit"></input><br>
<b>Resultado da soma:</b>
</div>
<div>
<?php
require_once '../model/numeros.php';
$o = new numeros();
$dados=$o->Somar();
echo $dados;
?>
</div>
My php class:
<?php
//$n1=$_GET['n1'];
//$n2=$_GET['n2'];
class numeros{
$n1=$_POST["n1"];
$n2=$_POST["n2"];
public function Somar()
{
$total=$n1+$n2;
return $total;
}
}
? >