| glsjr 2007-02-18, 12:21 am |
| I have a small problem. I am processing form data that I submitted using POST. Here is the code that I wrote to sanitize the data before processing and then add it to the session to pass onto the next script:
foreach ($_POST as $key => &$value) {
if (is_array($value)){
foreach ($value as $key2 => &$value2) { // Handle two dimensional datasets
$value2 = trim(strip_tags($value2));
echo "2 $key.$key2 = $value2<br />\n"; // This is for debugging only
}
} else {
$value = trim(strip_tags($value));
echo "1 $key = $value<br />\n"; // This is for debugging only
}
}
$_SESSION[search_criteria]= array();
$_SESSION[search_criteria]=$_POST;
// for debugging purposes, I then traverse and echo $_SESSION[search_criteria]
The problem is that between the end of the "foreach" and the assignment to the session, the value of the last form field gets over-written with the value of the next to last field. For example:
1 form_type = hs_search
1 hs_first =
1 hs_middle =
<snip other fields... />
1 hs_dcity =
1 hs_state = 6
1 hs_cem = 55,16
in second testing section
form_type is "hs_search"
hs_first is ""
hs_middle is ""
<snip other fields... />
hs_dcity is ""
hs_state is "6"
hs_cem is "6"
Does anyone see what's wrong? I've been over this several times and I can't see where the problem is. Any help would be *greatly* appreciated! |