Páginas

8 de abril de 2013

Como usar condicionales con PHP


<html>
<head>
<title>Como usar condicionales con PHP</title>
</head>
<body>
<?php
if(isset($_POST['enviar']))
{
if(count($_POST['respuesta']) == 0)
{
echo "Debe ingresar una respuesta";
}else{
if(!is_numeric($_POST['respuesta']))
{
echo "Ingrese un numero como respuesta.";
}else{
$rs = $_POST['a'] * $_POST['b'];
if($_POST['respuesta'] == $rs)
{
echo "Quien lo diria, si sabes multiplicar.";
}else{
echo "Mal muy mal.";
}
}
}
}
$a = mt_rand(1,12);
$b = mt_rand(1,12);
?>
<h3>Cuanto es: <?php echo $a." X ".$b; ?></h3>
<form method="POST">
<input type="text" name="respuesta" value="">
<input type=hidden name="a" value="<?php echo $a;?>">
<input type=hidden name="b" value="<?php echo $b;?>">
<input type=submit name="enviar" value="Responder">
</form>
</body>
</html>

0 comentarios:

Publicar un comentario

Gracias por tu visita