Ver Mensaje Individual
  #4 (permalink)  
Antiguo 09/03/2012, 17:22
Bitbreak
 
Fecha de Ingreso: mayo-2010
Mensajes: 6
Antigüedad: 14 años
Puntos: 0
Respuesta: Juego Calculo mental en PHP

Me sale el siguiente error:

Notice: Undefined index: respuesta in G:\xampp\htdocs\Juegocalculomental\resultado.php on line 2

Notice: Undefined index: suma in G:\xampp\htdocs\Juegocalculomental\resultado.php on line 3
Correcto. ¿Otra partida?


Os dejo como están ambos archivos tras leer vuestros comentarios:

index.php:

Código PHP:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<body>
<div align="center">
<?php

mt_srand
(time());

$valor1mt_rand(0,9);
$valor2mt_rand(0,9);

$suma=$valor1+$valor2;
    
/* @var $valor2 type */
echo "¿Cuánto es ".$valor1." + ".$valor2."?";


?>
</div>

<div align="center"><form metoh="POST" action="resultado.php">
<table>
<tr>
<td align="right">Es:</td>
<td align="right"><input type="text" size="5" name="respuesta">
<input type="hidden" size="5" name="suma" value="<?php echo $suma?>">

</td>
</tr>
<tr>
<td><input type="submit"></td>
<td><div align="center"><input type="button" value="Reiniciar juego" onClick="window.location.reload()"></div></td>
</tr>
</table>
</form>
</div>

</body>
</html>
resultado.php:

Código PHP:
<?php
$resultado 
$_POST['respuesta'];
$suma $_POST['suma'];


if (
$resultado == $suma){
echo 
"Correcto. <a href=\"index.php\"> &iquest;Otra partida?</a>";
}

else {
echo 
"Has fallado. El resultado es: ".$suma;
}

?>