使用提取来提取后美元变量

Hi im trying to build a foreach of sort of , that would extract($_POST) then utf8_decode each post so i dont have to do this manually for each $ variable, is it easy to make such function, im tired..thanks for any help.

Instead of writing every variable into query by hand, you can just name the field names, by using this simple function to produce SET statement:

function dbSet($fields) {
  $set='';
  foreach ($fields as $field) {
    if (isset($_POST[$field])) {
      $set.="`$field`='".mysql_real_escape_string($_POST[$field])."', ";
    }
  }
  return substr($set, 0, -2); 
}

and usage as simple as:

$fields = explode(" ","name surname lastname address zip fax phone");
$query  = "UPDATE $table SET ".dbSet($fields)." WHERE id=$id";

Neat, eh?