Advertisement
erprom

suma y resta

Mar 22nd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>sumar y restar</title>
  6.     <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  7.     <link rel="stylesheet" href="./styles/css/bootstrap.min.css">
  8.     <link rel="stylesheet" href="./styles/js/bootstrap.min.js">
  9.     <link rel="stylesheet" href="./styles/js/jquery-3.2.1.min.js">
  10.     <link rel="stylesheet" href="./styles/js/popper.min.js">
  11. </head>
  12. <body>
  13.     <div class="container">
  14.         <div class="row">
  15.             <div class="col">
  16.                 <!-- formulario -->
  17.                 <form action="sumaresta.php" method="post">
  18.                     <div class="form-group">
  19.                         <label for="num1">Numero 1</label>
  20.                         <input type="text" name="num1" id="num1" class="form-control">
  21.                     </div>
  22.                     <div class="form-group">
  23.                         <label for="num2">Numero 2</label>
  24.                         <input type="text" name="num2" id="num2" class="form-control">
  25.                     </div>
  26.                     <div class="form-group">
  27.                         <select name="operacion" id="operacion">
  28.                             <option value="suma">Suma</option>
  29.                             <option value="resta">resta</option>
  30.                         </select>
  31.                     </div>
  32.                     <div class="form-group">
  33.                         <input type="submit" value="enviar" name="enviar">
  34.                     </div>
  35.  
  36.                 </form>
  37.             </div>
  38.         </div>
  39.         <div class="row">
  40.             <div class="col">
  41.                 <?php
  42.  
  43.                 if (isset($_POST['enviar'])) {
  44.                     $num1 = $_POST['num1'];
  45.                     $num2 = $_POST['num2'];
  46.                     $operacion = $_POST['operacion'];
  47.  
  48.                 function suma($num1,$num2){
  49.                     $resultado = $num1 + $num2;
  50.                     return $resultado;
  51.                 }
  52.                 function resta($num1,$num2){
  53.                     $resultado = $num1 - $num2;
  54.                     return $resultado;
  55.                 }
  56.                 if ($operacion == "suma") {
  57.                     echo suma($num1,$num2)."<br>";
  58.                 }else{
  59.                     echo resta($num1,$num2)."<br>";
  60.                 }
  61.  
  62.                 }else{
  63.                     echo "no hay datos";
  64.                 }
  65.                 $solsuma = suma($num1,$num2);
  66.                 $solresta = resta($num1,$num2);
  67.  
  68.                 echo "el resultado de la operacion si es una suma es $solsuma <br>";
  69.                 echo "el resultado de la operacion si es una resta es $solresta";
  70.  
  71.  
  72.                 ?>
  73.             </div>
  74.         </div>
  75.     </div>
  76.    
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement