For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > February 2007 > $_POST Processing Problem









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author $_POST Processing Problem
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!
glsjr

2007-02-19, 3:10 pm

Problem solved. I pulled just that processing code out of the script (and left all of the debugging junk) and put it into a fresh file, and voila! it worked. It must have been a problem with all of the code that I was using to try to find problems. Sigh. At least I've got this problem fixed and can work on the next one...
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com