How come this function works, but the one below does not??
function clearContactVars()
{
global $contact_id; $contact_id = "";
global $contact_timestamp; $contact_timestamp = "";
global $contact_incept; $contact_incept = "";
global $contact_dept_table_id; $contact_dept_table_id = "";
global $contact_fname; $contact_fname = "";
global $contact_lname; $contact_lname = "";
global $contact_title; $contact_title = "";
global $contact_phone; $contact_phone = "";
global $contact_email; $contact_email = "";
global $contact_address1; $contact_address1 = "";
global $contact_address2; $contact_address2 = "";
global $contact_city; $contact_city = "";
global $contact_state; $contact_state = "";
global $contact_zip; $contact_zip = "";
global $contact_country; $contact_country = "";
global $contact_notes; $contact_notes = "";
}
This one does NOT work the way I would expect it to?
function clearContactVars()
{
foreach ($GLOBALS as $key => $value) {
if ( substr($key,0,8) == "contact_" ) {
//echo "GLOBALS['$key'] = $value<br>\n";
$GLOBALS['$key'] = "";
}
}
clearPostVars();
}
(this is located in an require() file and do I even need to do this?):
function clearPostVars()
{
foreach ($_POST as $key => $value) {
//echo "_POST['$key'] = Value: $value<br>\n";
$_POST['$key'] = "";
}
}
I use these variables on a web page like so:
<TR>
<TD ALIGN="RIGHT"><B>Phone:</B></TD>
<TD><INPUT Name="contact_phone" Value="<?=$contact_phone?>"></TD>
</TR>
So after a successful insert/update/whatever, I need to clear the fields.
The only other relevant part is that at the top of each page in a require()
file, I have this:
reset ($_POST);
while (list ($key, $val) = each ($_POST)) {
//echo "$key => $val<br>\n";
$$key = $val;
}
But it doesn't make sence to me that the first function does in fact clear
the variables, when the second one does not. I thought that would be even
more direct, since "global $contact_id" from what I read is only a reference
to the global variable named $contact_id. Which in effect should be exactly
$GLOBALS['contact_id'] right?
http://www.php.net/manual/tw/migration4.variables.php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php