Generalized PHP function for editing data in a table
Simply put, this code fails a lot best practices also contains massive security issues.
Suggestion to improve for best practices:


  $GLOBALS["HTTP_POST_VARS"] is deprecated in favor of $_POST


So you looping over $GLOBALS["HTTP_POST_VARS"] and $_POST is redundant and bad mojo. Just looping over $_POST will accomplish the same thing. Same goes for $GLOBALS["HTTP_GET_VARS"] and $_GET.


  You should be passing in the $link object as parameter. 


Since there is no code intended to change the database connection conditionally (the connect parameters are always the same). This prevents your scripts creating multiple database connection resources and destroying them (more memory and time consuming). Also passing in the database resource as parameter to the function is a type of dependency injection which makes your code testable should you want to in the future. Since this also appears to be in a class, consider creating the database connection in the __construct and use that single instance.


  Using sessions in favor of $GLOBALS


Pretty much any use of $GLOBALS is considered bad practice. I'm sure there are a few exceptions to the rule. But there you should definitely not be using is for storing data in a scopeless fashion. This is what sessions are for.


  removeQuotes() is never called on $fldname or $fldval


As you can imagine this a serious security issue leaving your script open to SQL Injection attacks.


  Use mysql_real_escape_string in favor of home made sanitising functions i.e. removeQuotes()


There is a lot more to safe escaping query parameters that remove slashes. And in my experience home made sanitising functions often quietly fail when you have mixed string and number parameters.

As a matter of readability and style I would make to following suggestions, I know these are subject matters but there are common ways of doing things.


  Substitute the use of string concatenation


$query.="`".$field."`=";
$query.="'".$this-&gt;removeQuotes($$field,$lang_flag)."' , ";
... more concatenation ...
$query = substr($query,0,-2);


for array joining

$queryParams[] = "`".$field."`='".$this-&gt;removeQuotes($$field,$lang_flag)."'";
... more array filling ...
$query = join(',', $queryParams);


General WTFs


  This is doing nothing at all $query  ;


And code that does nothing is very bad mojo.


  Call count() once.


This is not really an issue, doing something like this 

for($p=0;$p

In actual fact calls count() on every iteration of the loop, even though the return value will never change. It causes the interpreter to do more work than necessary, although I suspect during compilation to byte code this would be optimised automatically. This could be substituted for:

// only call count() once
$count = count($arr_types);
for($p=0;$p&lt;$count;$p++)



  Don't nest unnecessarily.


Don't nest conditionals (if/else/switch) and loop(while/for) unnecessarily. It makes for messier code, code that's harder to read and follow mentally, and importantly difficult to test.

if(isset($$field))
{
     $query.="`".$field."`=";

     $query.="'".$this-&gt;removeQuotes($$field,$lang_flag)."' , ";
 }
 else
 {
     if(isset($GLOBALS["$field"]))
     {
         $query.="`".$field."`=";
         $query.="'".$this-&gt;removeQuotes($GLOBALS["$field"],$lang_flag)."' , ";
     }
 }


The above code is exactly equal to the following, notice less nesting.

if(isset($$field))
{
     $query.="`".$field."`=";

     $query.="'".$this-&gt;removeQuotes($$field,$lang_flag)."' , ";
 }
 else if(isset($GLOBALS["$field"]))
 {
         $query.="`".$field."`=";
         $query.="'".$this-&gt;removeQuotes($GLOBALS["$field"],$lang_flag)."' , ";
 }


Personal preference


  This is completely subjective, but something to think about.


if(stristr($k,$arr_types[$p])!="")


equal to

if(stristr($k,$arr_types[$p]) == true)


equal to

if(stristr($k,$arr_types[$p]))



  Considering the above, this:


while (list($k,$v)=each($_GET)) 
{
    for($p=0;$p &lt; count($arr_types);$p++)
    {
        if(stristr($k,$arr_types[$p])!="")
        {
            $k = str_replace($arr_types[$p],"",$k);
        }
    }
    ${strtolower($k)}=$v;
}


Is exactly the same as:

while (list($k,$v)=each($_GET)) 
{
    $count = count($arr_types);
    for($p=0; $p&lt;$count; $p++);
    {
        $k = str_replace($arr_types[$p],"",$k);
    }
    ${strtolower($k)}=$v;
}  


Which would you rather test and/or work with?