I've got some legacy code which I need to maintain and its got this function which works perfectly fine, but I'm trying to understand if it is working using acceptable coding practices or not... I am trying to understand if it is safe and secure to operate the site with the function as-it-is.
The function would be called as:
$this->editData('users',"activation_key",$_GET['key']);
The actual function (unedited):
function editData($table_name,$fldname,$fldval,$other='',$lang_flag=0)
{
$link = $this->my_connect();
$this->my_select_db($this->DATABASE_NAME,$link);
$arr_types = array("TR_", "TN_", "TREF_", "PHR_", "PHN_", "IR_", "IN_", "MR_", "MN_", "TNEF_", "TRC_", "TNC_", "TRFN_", "TNFN_","TNURL_","TRURL_");
if (!empty($GLOBALS["HTTP_POST_VARS"])) {
reset($GLOBALS["HTTP_POST_VARS"]);
while (list($k,$v)=each($GLOBALS["HTTP_POST_VARS"]))
{
for($p=0;$p<count($arr_types);$p++)
{
if(stristr($k,$arr_types[$p])!="")
{
$k = str_replace($arr_types[$p],"",$k);
}
}
${strtolower($k)}=$v;
//echo "<br> k =$k -- v = $v";
}
}
if (!empty($_POST)) {
reset($_POST);
while (list($k,$v)=each($_POST))
{
for($p=0;$p < count($arr_types);$p++)
{
if(stristr($k,$arr_types[$p])!="")
{
$k = str_replace($arr_types[$p],"",$k);
}
}
${strtolower($k)}=$v;
//echo "<br> k =$k -- v = $v";
}
}
if (!empty($GLOBALS["HTTP_GET_VARS"])) {
reset($GLOBALS["HTTP_GET_VARS"]);
while (list($k,$v)=each($GLOBALS["HTTP_GET_VARS"]))
{
for($p=0;$p < count($arr_types);$p++)
{
if(stristr($k,$arr_types[$p])!="")
{
$k = str_replace($arr_types[$p],"",$k);
}
}
${strtolower($k)}=$v;
//echo "<br> k =$k -- v = $v";
}
}
if (!empty($_GET)) {
reset($_GET);
while (list($k,$v)=each($_GET))
{
for($p=0;$p < count($arr_types);$p++)
{
if(stristr($k,$arr_types[$p])!="")
{
$k = str_replace($arr_types[$p],"",$k);
}
}
${strtolower($k)}=$v;
//echo "<br> k =$k -- v = $v";
}
}
$result=$this->my_query("show fields from $table_name",$link);
$query="update $table_name SET ";
while ($a_row = $this->my_fetch_array($result)) {
$field="$a_row[Field]";
if($field!=$fldname)
{
if(isset($$field))
{
$query.="`".$field."`=";
$query.="'".$this->removeQuotes($$field,$lang_flag)."' , ";
}
else
{
if(isset($GLOBALS["$field"]))
{
//echo "<br> var ".$GLOBALS["$field"];
$query.="`".$field."`=";
$query.="'".$this->removeQuotes($GLOBALS["$field"],$lang_flag)."' , ";
}
}
}
}
$query = substr($query,0,-2);
$query.=" where `$fldname`='$fldval' $other";
$query ;
//echo $query;
$result=$this->my_query($query,$link);
$this->my_free_result($result);
$this->my_close($link);
return $result;
}