I don't see any variable variables.
Incidentally, since you only ever use the array keys when you're looping
foreach(array_keys($variables) as $variable)
would save the redundant $title variable from floating around. And since you're using an array, there might be some array functions that would simplify what you're doing. E.g.,
$v=0;
foreach ($variables as $variable => $title) {
if($v) $sql.= ', ';
$sql.= $variable;
$v++;
}
could be replaced by
$sql .= join(", ", array_keys($variables));
and
$v=0;
foreach ($variables as $variable => $title) {
if($v) $sql.= ', ';
$sql.= "'".mysql_escape_string(trim($_REQUEST[$variable]))."'";
$v++;
}
by
$request_values = array_intersect_key($_REQUEST, $variables));
$request_values = array_map('mysql_escape_string',(array_map('trim', $request_values));
$request_values = array_map(create_function('$a','return "\'$a\'";'), $request_values);
$sql .= join(", ", $request_values);
although it would be tidier to have a distinct function to do that trimming, escaping, and quoting, and write
$sql .= join(', ', array_map('prep_variable', array_intersect_key($_REQUEST, $variables)));
And then of course there's PDO: then the escaping and quoting steps wouldn't be needed.