Calculadora de edad.
Escribir en código PHP que al solicitar la fecha de nacimiento por medio de un formlario nos diga cual es la edad del usuario, utilizando radio buttons determina el sexo y utilizando select determina su nivel de estudios y que estos valores se impriman en una segunda ventana.
Creación del formulario.
formulario.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
*{
margin:0px;
padding:0px;
}
body{
background-position:center;
}
form{
background: #0097A7;
width: 500px;
border:1px solid #4e4d4d;
border-radius: 3px;
-moz-border-radious:3px;
-webkit-borde-radious:3px;
box-shadow:inset 0 0 10px #000;
margin:100px auto;
}
form h6{
text-align: center;
color:#000000;
font-weight: normal;
font-size: 20pt;
margin:30px 0px;
}
form input{
width:280px;
height: 25px;
padding: 0px 10px;
margin:10px 30px;
color:#00BFFF;
text-align: center;
}
}
form button{
width:135px;
margin:20px 0px 30px 30px;
height: 50px;
}
form button:hover{
background:#3a3a3a;
}
</style>
</head>
<body background>
<form method="post" action= "edad.php">
<center>
<h3>Calculadora de edad</h3>
</center>
<strong>Ingrese su nombre:
<input type="text" name="nombre">
<br><br>
Ingrese día de nacimiento:
<input type="text" name="dia">
<br><br>
Ingrese mes de nacimiento:
<input type="text" name="mes">
<br><br>
Ingrese año de nacimiento:
<input type="text" name="año">
<br><br>
Sexo:<br>
Masculino<input type="radio" name="radio1" value="masculino">
<br>
Femenino<input type="radio" name="radio1" value="femenino">
<br><br>
Nivel de estudios:
</strong>
<br><br>
<center>
<select name="nivel">
<option value="primaria">Primaria</option>
<option value="secundaria">Secundaria</option>
<option value="bachillerato">Bachillerato</option>
<option value="universidad">Universidad</option>
</center>
</select>
</select>
<br><br>
<input type="submit" value="Enviar">
</form>
</body>
</html>
Impresión de datos.
edad.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body background="homer.jpg">
<h1>Calculadora de edad </h1>
<?php
$nombre= $_REQUEST['nombre'];
$dia= $_REQUEST['dia'];
$mes= $_REQUEST['mes'];
$año= $_REQUEST['año'];
echo "Hola",$nombre,"<br>","Tus datos ingresados fueron:<br><br>","Día:",$dia,"<br>","Mes:",$mes,"<br>","Año:",$año,"<br>";
if($mes <=3 && $dia<30){
$edad=(2017-$año);
echo "Tu edad es:",$edad,"años","<br>";
}
else if($mes>3){
$edad=(2017-$año)-1;
echo "Tu edad es:",$edad,"años","<br>";
}
else if($mes>=3 && $dia>29){
$edad=(2017-$año)-1;
echo "Tu edad es:",$edad,"años","<br>";
}
if($mes==3 && $dia==29){
$edad=(2017-$año);
echo "<br>Estas son las mañanitas","<br>","Que cantaba el rey David","<br>","Hoy por ser día de tu santo","<br>","Te las cantamos a ti","<br>","Despierta, mi bien,despierta","<br>","Mira que ya amaneció","<br>","Ya los pajaritos cantan","<br>","La luna ya se metió","<br><br>";
}
if($_REQUEST['radio1']== "femenino"){
echo "Sexo:Femenino<br>";
}
else{
echo "Sexo:Masculino<br>";
}
if($_REQUEST['nivel']=="primaria"){
$nivel="Primaria";
}
else if($_REQUEST['nivel']=="secundaria"){
$nivel="Secundaria";
}
else if($_REQUEST['nivel']=="bachillerato"){
$nivel="Bachillerato";
}
else{
$nivel="Universidad";
}
echo "Tu nivel de estudios es:",$nivel;
?>
</body>
</html>