Just for kicks.. this is an even better approach to 2 and 3:
// dynamic.php
if (isset($_POST["number"]) && is_numeric($_POST["number"]))
{
for ($i = 1; $i <= $_POST["number"]; $i++)
{
echo "Please enter the name of child {$i}:";
echo "<input type='text' name='child[]' /><br />";
}
}
else
{
echo "Error: you did not enter a valid number!";
}
http://www.php.net/is_numeric
The use of this function ensures that the data provided is a number. isset ensures that it exists, without isset if the variable did not exist you would get a notice level error.
// dynamic2.php
if (isset($_POST["child"]) && is_array($_POST["child"]))
{
for ($i = 0; $i < count($_POST["child"]); $i++)
{
if (!empty($_POST["child"][$i]))
{
$_POST["child"][$i]."<br />";
}
else
{
echo "You did not enter child #".($i+1)."'s name";
}
}
}
else
{
echo "You did not enter any of your children's names";
}
http://www.php.net/is_array
The use of is_array ensures that the variable is an array.
I am also using register_globals = off, which is why I use the $_POST superglobal array. Hundreds, if not thousands of posts on this topic in p2p alone.
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::