error en algo creo que sencillo
hola, estoy haciendo un pekeño ejercicio en el ke escribo un numero en un cuadro de texto de un formulario y, me lo manda a la misma página para hacer una suma recursiva.... osea si le pongo 5 me devuelve 1+2+3+4+5
el problema no lo tengo aki, lo ke me ocurre es ke cuando vuelvo a escribir otro número después en el cuadro de texto e intento hacer otra suma, me da un error.
Aqui os dejo el codigo a ver si alguien me dice ke pasa:
<html>
<head><title>suma recursiva</title></head>
<body onload="document.formulario.numero.focus()">
<?
if ($_GET[numero]=="")
{
echo "<form action="suma-recursiva02.php" method="get" name="formulario">";
echo "Escribe un numero: <input type="text" name="numero"><br>";
echo "<input type="submit" value="calcular">";
echo "</form>";
}
else
{
echo "<form action="suma.php" method="get" name="formulario">";
echo "Escribe un numero: <input type="text" name="numero" value="".$_GET[numero].""><br>";
echo "<input type="submit" value="calcular">";
echo "</form>";
$num=$_GET[numero];
for($i=1;$i<=$num;$i++)
{
$total = $total + $i/$i;
if($i<$num)
{
echo $total."+";
}
else
{
echo $total;
}
}
}
?>
</body>
</html>
muchas gracias, saludos.
el problema no lo tengo aki, lo ke me ocurre es ke cuando vuelvo a escribir otro número después en el cuadro de texto e intento hacer otra suma, me da un error.
Aqui os dejo el codigo a ver si alguien me dice ke pasa:
<html>
<head><title>suma recursiva</title></head>
<body onload="document.formulario.numero.focus()">
<?
if ($_GET[numero]=="")
{
echo "<form action="suma-recursiva02.php" method="get" name="formulario">";
echo "Escribe un numero: <input type="text" name="numero"><br>";
echo "<input type="submit" value="calcular">";
echo "</form>";
}
else
{
echo "<form action="suma.php" method="get" name="formulario">";
echo "Escribe un numero: <input type="text" name="numero" value="".$_GET[numero].""><br>";
echo "<input type="submit" value="calcular">";
echo "</form>";
$num=$_GET[numero];
for($i=1;$i<=$num;$i++)
{
$total = $total + $i/$i;
if($i<$num)
{
echo $total."+";
}
else
{
echo $total;
}
}
}
?>
</body>
</html>
muchas gracias, saludos.