I am working with a set of variables that i check each time a page loads. I have successfully checked through $_REQUEST and $_SESSION, but am having trouble with the dynamci checking of variables assigned higher int he page, if they were set.
the following is my code:
$important_field = array('treatmentId','category','state','providerId','sellDoc','insuranceName','grossCharge','discount','allowable','patientPortion','insurancePortion','dateOfService','billFileLocation','eobFileLocation','fromTable');
foreach ($important_field as $key) {
if (!$$key || $$key == "none" || $$key == "" || $$key == NULL) {
if (!$_REQUEST[$key] || $_REQUEST[$key] == "" || $_REQUEST[$key] == NULL) {
if (!$_SESSION[$key]) {
// wow, guess it just wasn't set anywhere...
} else {
$user->sell->$key = $_SESSION[$key];
}
} else {
$user->sell->$key = $_REQUEST[$key]; $_SESSION[$key] = $_REQUEST[$key];
}
} else {
$user->sell->$$key = $$key; $_SESSION[$$key] = $$key;
}
}
Apparently evaluating $$key does not seem to do what i'm looking for as it never assigns the variable to the session... how should I be evaluating the $key to get the currently set value of say, field $eobFileLocation if it was already set in the PHP prior to the check?
Thanks,
Silver Tiger
Update:
ok, i have the following code, but there's still one bug with it. When i follow my process through af ew of these variables are set on each page and are carried over by the session variable as expected. The issue I am still having is that when i submit a new $_REQUEST variable which SHOULD change the session variable to the new submitted value, the script is finding a local variable ... where is it pulling $key and $$key from that is finding these as a local variable?
$important_field = array('treatmentId','category','state','city','providerId','sellDoc','insuranceName','grossCharge','discount','allowable','patientPortion','insurancePortion','dateOfService','billFileLocation','eobFileLocation','fromTable');
foreach ($important_field as $key) {
if (isset($$key) && !empty($$key) && $$key != "none") {
echo "Found local variable for ".$key.", i'll set the session and user to this.<br>\n";
$user->sell->$key = $$key;
$_SESSION[$key] = $$key;
} elseif (isset($_REQUEST[$key]) && !empty($_REQUEST[$key])) {
echo "Found submitted form variable for ".$key.", i'll set the session and user to this.<br>\n";
$user->sell->$key = $_REQUEST[$key];
$_SESSION[$key] = $_REQUEST[$key];
} elseif (isset($_SESSION[$key]) && !empty($_SESSION[$key])) {
echo "Found a session variable ".$key.", i'll set the user to this.<br>\n";
$user->sell->$key = $_SESSION[$key];
} else {
echo "There was no provided data for ".$key."<br>\n";
}
}
Any ideas why when i load the page it thinks the local (as listed above) is set? does $key and $$key read from $_SESSION['blah']/$_REQUEST['blah'] and think it's just $blah?
$_REQUEST, else if it's set in$_SESSION, then use the first matching value for your$userobject?"none", you should first work on internal consistency and data management.