Mortgage Calculator - Loan - Bad Credit Mortgages - Debt Help - Loans

PDA

View Full Version : Retrieving $_POST data question


NoamBarz
May 9th 2007, 6:36 am
I have an HTML form that is created by selecting data from a mysql table. The page gets the table name as a variable and creates the form by looping through the table fields (not the values within the fields). I used mysql_fetch_field in order to do this. Displaying the form and validating it, on the client's side, is no problem at all.

My problem starts when I submit the form. The form action is set to a page "X" and uses the method POST. Is there a way for me to retrieve the POST data without knowing the form field names? I know $_POST is an array, so there must be a way ($_POST[index number] doesn't work).

In english, what I would like to do is:

for each field in $_POST fields do something.

I could, I suppose, retrieve the field names from the mysql table before reading the post data and in this way know what the field names are. However, I'm sure there's a better way. Does anyone know of a solution?

nico_swd
May 9th 2007, 6:42 am
foreach ((array)$_POST AS $index => $value)
{
// $index = Field name
// $value = Field value
}

NoamBarz
May 9th 2007, 6:48 am
Thanks a lot!! Rep added.

NoamBarz
May 9th 2007, 7:15 am
nico_swd's method works like a charm - thanks again.
However, if by any chance someone is also using input type='file' fields, that person would also have to loop through the FILE array:

foreach((array)$_FILES AS $index => $value){
echo $index . " = " . $value['tmp_name'] ."<br>";
}

just a tip

gibex
May 10th 2007, 6:59 pm
(array) cast before $_FILES can be removed in case of register_globals = off

another tip.