Question 1:
if(mysql_error() != '') {
header("Location: errorDoc.php");
exit;
}
Question 2:
$inputString = $_POST['fieldName'];
$inputString = str_replace('.', '_', $inputString); // replace periods
$inputString = str_replace(' ', '_', $inputString); // replace space
$inputString = str_replace('__', '_', $inputString); // replace possible double underscores