rootman103
asked on
passing form data to an array
Experts,
I have created a simple form with a text box to place ips in.
i called the text box id='ips'
when i submit, it goes to a script page with the following code,
$times = "5";
//$lines = file("myips.txt");
print $_POST["ips"];
$arr = array( $_POST["ips"]=>$ips);
echo "<pre>";
foreach ($arr as $ip => $ips)
{
passthru("ping -c $times $ips");
}
echo "</pre>";
What i am trying to do, is be able to put 20 ips in my form and have the for each statement loop through each ip provided by the form so it pings each ip x times and displays the results on the screen.
the above model works but only pings the first ip in the array and ignores the rest.
can anyone tell me where i have messed this up?
THanks,
Rootman103
I have created a simple form with a text box to place ips in.
i called the text box id='ips'
when i submit, it goes to a script page with the following code,
$times = "5";
//$lines = file("myips.txt");
print $_POST["ips"];
$arr = array( $_POST["ips"]=>$ips);
echo "<pre>";
foreach ($arr as $ip => $ips)
{
passthru("ping -c $times $ips");
}
echo "</pre>";
What i am trying to do, is be able to put 20 ips in my form and have the for each statement loop through each ip provided by the form so it pings each ip x times and displays the results on the screen.
the above model works but only pings the first ip in the array and ignores the rest.
can anyone tell me where i have messed this up?
THanks,
Rootman103
ASKER
This code works great, but is there a way to make it so instead of haviing individual boxes for each ip to have it be one big text field and get the same result?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Awesome.
This works perfectly.
Thanks
This works perfectly.
Thanks
Example:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>My page</title>
</head>
<body>
<?
if(isset($_POST['sendValue
$times = "5";
for($no=0;$no<count($_POST
$ips = $_POST['ips'][$no];
passthru("ping -c $times $ips");
}
}
?>
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<?
for($no=0;$no<10;$no++){
echo "<input type=\"text\" name=\"ips[]\"><br>\n";
}
?>
<input type="submit" name="sendValues">
</form>
<div id="myDiv">This is the content of this div</div>
</body>
</html>