kenoli Posted June 3, 2008 Share Posted June 3, 2008 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 More sharing options...
justsomeguy Posted June 3, 2008 Share Posted June 3, 2008 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 More sharing options...
kenoli Posted June 4, 2008 Author Share Posted June 4, 2008 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.