PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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:
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
Last edited by RobertGonzalez on Mon Jun 02, 2008 11:05 pm, edited 1 time in total.
Reason:Please use appropriate bbCode tags when posting code in the forums
PS You may want to use isset() when checking array values.
PPS You might also not want to check a form buttom for your form submission. What happens if the button doesn't send? Try look at the $_SERVER['HTTP_REQUEST_METHOD'] being equal (==) to 'POST'
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$testcount = count($_POST['test']);
$whencount = count($_POST['when']);
for ($i = 0; $i < $testcount; $i++) {
// Do what you need to with $_POST['test'][$i]
}
for ($i = 0; $i < $whencount; $i++) {
// Do what you need to with $_POST['when'][$i]
}
}
?>
If you are certain that the arrays will be the same size you can handle both test and when processes in the same loop.
Everah -- Thanks for your attention and patience. Your solution makes a lot sense for accessing the data from each array. I'm not sure if it gets me what I need. I'm still feeling a bit clueless.
I'm trying to update a database with a query made up of elements from each array combined into one query.
Something like:
Take the first element of the first array, give it the formatting it needs for the query, add the same from the next array and so on with other arrays, update that record and then increment up to the next element and do the same.
The code you set up would mean looping all the way through the first array and then looping all the way through the next, etc.
I guess I could put the data from the first loop into an array with the appropriate formatting for the query, the same with the others and then somehow concatenate the elements of all the arrays and then loop through the resulting array, making the database update with each element.
Or, update the first column of the first record, the second column of the first record, the third column of the first record, etc. and then on the do the same thing with each subsequent record and columns associated with it. This is a lot of updates.
Both of these approaches seem so roundabout.
Am I missing something?
Maybe I should have asked the question differently.
Like: If one has an html form with data in it from a bunch of database records, how would one allow a user to go through the form, make edits on a number of records and then post the whole thing to be updated by one script? What would the script look like?