A continuación os muestro el código:
<form method="post" action="capitulo8.php">
Valor1:<input type="text" name="variable1">
valor2:<input type="text" name="variable2">
<select name="operacion">
<option value="sumar">sumar</option>
<option value="restar">restar</option>
<option value="multiplicar">multiplicar</option>
<option value="dividir">dividir</option>
</select>
<input type="submit" value="enviar">
</form>
<?php
if (isset($_POST['variable1'])){
if($_POST['operacion']=="sumar"){
$resultado=$_POST['variable1']+$_POST['variable2'];
echo "la suma de".$_POST['variable1']."+".$_POST['variable2']." es ".$resultado;
}else if($_POST['operacion']=="restar"){
$resultado=$_POST['variable1']-$_POST['variable2'];
echo "la resta de".$_POST['variable1']."-".$_POST['variable2']." es ".$resultado;
}else if($_POST['operacion']=="multiplicar"){
$resultado=$_POST['variable1']*$_POST['variable2'];
echo "la multiplicación de".$_POST['variable1']."-".$_POST['variable2']." es ".$resultado;
}else if($_POST['operacion']=="dividir"){
$resultado=$_POST['variable1']/$_POST['variable2'];
echo "la división de".$_POST['variable1']."/".$_POST['variable2']." es ".$resultado;
}
}
?>
Si teneis cualquier consulta escribidme en comentarios y os la resolveré encantadamente.
No hay comentarios:
Publicar un comentario