Jump to content

Accessing multiple arras from a post submission.


kenoli
 Share

Recommended Posts

I am trying to capture the data from a form with several fields in a way that I can update a number of database records, each with several fields, from one form submittal. I can capture the data from one of the form inputs like this:<?phpif ($_POST['Submit']) { foreach($_POST['test'] as $key => $value) { echo $value . '<br/>'; }}?><form name="form1" method="post" action="<?=$_SERVER['PHP_SELF'] ?>"> Test: <input type="text" name="test[]" id="textfield"><br> When: <input type="text" name="when[]" id="textfield"><br> Test: <input type="text" name="test[]" id="textfield"><br> When: <input type="text" name="when[]" id="textfield"><br> Test: <input type="text" name="test[]" id="textfield"><br> When: <input type="text" name="when[]" id="textfield"><br> Test: <input type="text" name="test[]" id="textfield"><br> When: <input type="text" name="when[]" id="textfield"><br> Test: <input type="text" name="test[]" id="textfield"><br> <input name="Submit" type="Submit"></form>Is there a way I can also capture the data from $_POST['when'] or even more similar field arrays?I'm sure there is a way to do this but can't see it. I would greatly appreciate help figuring this out.Thanks,--Kenoli

Link to comment
Share on other sites

You can use a for loop or a foreach loop to go through the arrays. If you can guarantee that both arrays have the same number of elements then you can use one loop to go through both arrays.

for ($i = 0; $i < count($_POST['test']); $i++){  echo $_POST['test'][$i];  echo $_POST['when'][$i];}

Link to comment
Share on other sites

Justsomeguy -- Thanks. It works perfectly and Makes me feel a bit foolish for not getting it on my own. I actually thought I had tried something like this and found that it didn't work. Must have been a syntactical error.Thanks again,--Kenoli

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...