hercioneto

pw1-2017 calculaIdade.php

Sep 28th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <!-- Arquivo: calculaIdade.php -->
  3. <html>
  4.     <head>
  5.         <meta charset="utf-8"/>
  6.         <title> Formulários </title>
  7.         <style>
  8.         label span { font-size: 14px; color: #666;
  9.         padding-left:26px;
  10.         width:125px;
  11.         text-transform: uppercase;
  12.         display:inline-block;  
  13.         }
  14.        
  15.         </style>
  16.     </head>
  17. <body>
  18. <h1> Vamos calcular sua idade</h1>
  19. <h2>Informe seus dados:</h2>
  20. <?php
  21. $data = $_POST["dataNasc"];
  22. $mes = $_POST["mesNasc"];
  23. $ano = $_POST["anoNasc"];
  24. ?>
  25. <label for="data">Data de Nascimento:</label>
  26. <span><?php echo $data; ?></span>
  27. <br/>
  28. <label for="mes">Mês de Nascimento:</label>
  29. <span><?php echo $mes; ?></span>
  30. <br/>
  31. <label for="ano">Ano de Nascimento:</label>
  32. <span><?php echo $ano; ?></span>
  33. <br/>
  34. <p>
  35. Sua idade é: <?php
  36. $anoAtual = 2017; //date("Y");
  37. $mesAtual = 9;//date("m");
  38. $diaAtual = 28;//date("d");
  39. $idade= $anoAtual-$ano;
  40.     if ($mes >= $mesAtual) {
  41.         $idade=$idade-1;
  42.     }      
  43.     if ($mesAtual == $mes) {
  44.         if ($data < $diaAtual) {           
  45.             $idade = $idade+1;
  46.         }
  47.     }
  48. echo $idade;
  49. ?>
  50. <p/>
  51. </form>
  52. </body>
  53. </html>
Add Comment
Please, Sign In to add comment