Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/08/2009, 05:28
Avatar de PacoRuiz
PacoRuiz
 
Fecha de Ingreso: abril-2009
Mensajes: 254
Antigüedad: 15 años
Puntos: 3
arrays en un formulario

Estoy intentando pasar por post una serie de datos en un array. En teoría sé cómo hacerlo, pero no me funciona. ¿Alguien me puede pasar un código que funcione? Tanto la parte del envío como de la recepción, porque no sé dónde tengo el error.

O bien ver dónde está el error aquí: ee cogido de un tutorial webtaller.com) el siguiente código:

html>
<head>
<title>Array en Forma :: PHP</title>
<head>
<body>
<br />
<b>Selecciona tus postres favoritos:</b><br /><br />
<form method="post" action="prueba2.php">
<input name="postre[]" type="checkbox" value="Helado de Vainilla">Helado de vanilla<br />
<input name="postre[]" type="checkbox" value="Pastel de Chocolate">Pastel de Chocolate<br />
<input name="postre[]" type="checkbox" value="Pay de elote">Pay de elote<br />
<input name="postre[]" type="checkbox" value="Bubulubu">Bubulubu<br />
<input name="postre[]" type="checkbox" value="Duraznos en almibar">Duraznos en almibar<br />
<input name="postre[]" type="checkbox" value="Fresas con crema">Fresas con crema<br />
<input name="send" type="submit" id="send" value="Enviar!">
</form>

<?php
if (isset($_POST['postre']))
{
$postre = $_POST['postre'];
$n = count($postre);
$i = 0;

echo "Tus postres favoritos son: rn" .
"<ol>";
while ($i < $n)
{
echo "<li>{$postre[$i]}</li> rn";
$i++;
}
echo "</ol>";
}
?>

</body>
</html>

Y lo recibo con el siguiente código:

?php
echo"hola";
$recibido=$_POST['postre[0]'];
echo "$recibido";
?>

Me escribe hola y ya está.