I had trouble using the accepted answer as it caused me errors for reasons I couldn't work out. So for anyone having trouble with array_walk or array_map I found this to work.
foreach($_POST as $pk => $pv) $_POST[$pk] = mysql_real_escape_string($pv);