0
<body>
<form role="form" action="pratica_fazer_calculadora.php" method="get">
<input type="number" placeholder="Digite um número" name="primeiro_numero"/>
<select>
<option value="1">Soma</option>
<option value="2">Subtração</option>
<option value="3">Divisão</option>
<option value="1">Multiplicação</option>
</select>
<input type="number" placeholder="Digite um número" name="segundo_numero"/>
<button type="submit">Ver resultado</button>
</form>
<?php
$num_1 = $_GET ['primeiro_numero'];
$num_2 = $_GET ['segundo_numero'];
$operacao[1] = 1;
$operacao[2] = 2;
$operacao[3] = 3;
$operacao[4] = 4;
$resultado = null;
if($operacao[1]){
$resultado = ($num_1 + $num_2);
}
echo $resultado;
?>
</body>
The interesting thing is that no error message appears.
What exactly isn’t working? What error returns?
– Geraldão de Rívia
There’s the problem. There’s simply no error message. It’s as if it took the data and disappeared with it.
– Sidiney Silva
The sum is happening, if you want the other operations to work, you need to define conditions for them too
– Geraldão de Rívia
I don’t know about you. But here the result is not printed on the screen. In yours it appears?
– Sidiney Silva
It worked here, but there’s some weird stuff on this calculator, I don’t know if it’s just a test, but there’s a lot of unnecessary stuff that can be simplified, I’ll post an example
– Geraldão de Rívia
@Bacco I tested his code here, and the sum(only operation) worked
– Geraldão de Rívia
"It’s like he takes the data and takes it away.".. rachei! rs :D
– Sam
@Shinchila_matadora works in the sense that it will add unconditionally, because the value of item 1 of the array is 1. In practice "it seems to work" only. It would be like you making one
echo 3
and say it works every time you test with 1 + 2 ...– Bacco