I have an online form with a large number of variables being stored in the $_POST array.
$ID = mysql_real_escape_string($_POST['ID']);
$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string($_POST['lastname']);
$address = mysql_real_escape_string($_POST['address']);
$city = mysql_real_escape_string($_POST['city']);
$state = mysql_real_escape_string($_POST['state']);
$zipcode = mysql_real_escape_string($_POST['zipcode']);
$birthdate = mysql_real_escape_string($_POST['birthdate']);
$telephone = mysql_real_escape_string($_POST['telephone']);
$email = mysql_real_escape_string($_POST['email']);
$pay_for_insurance = mysql_real_escape_string($_POST['group1'] == 'pay_for_insurance' ? 1 : 0);
$dont_pay_for_insurance = mysql_real_escape_string($_POST['group1'] == 'dont_pay_for_insurance' ? 1 : 0);
$self_employed = mysql_real_escape_string($_POST['group2'] == 'self_employed' ? 1 : 0);
$not_self_employed = mysql_real_escape_string($_POST['group2'] == 'not_self_employed' ? 1 : 0);
$has_health_insurance = mysql_real_escape_string($_POST['group3'] == 'has_health_insurance' ? 1 : 0);
$no_health_insurance = mysql_real_escape_string($_POST['group3'] == 'no_health_insurance' ? 1 : 0);
$has_cobra = mysql_real_escape_string($_POST['group4'] == 'has_cobra' ? 1 : 0);
$no_cobra = mysql_real_escape_string($_POST['group4'] == 'no_cobra' ? 1 : 0);
$current_ins = mysql_real_escape_string($_POST['current_ins']);
$employees = mysql_real_escape_string($_POST['employees']);
$dep1 = mysql_real_escape_string($_POST['dep1']);
$dep2 = mysql_real_escape_string($_POST['dep2']);
$dep3 = mysql_real_escape_string($_POST['dep3']);
$smoker = mysql_real_escape_string($_POST['group5'] == 'smoker' ? 1 : 0);
$non_smoker = mysql_real_escape_string($_POST['group5'] == 'non-smoker' ? 1 : 0);
$health = mysql_real_escape_string($_POST['health'] == 'health' ? 1 : 0);
$life = mysql_real_escape_string($_POST['life'] == 'life' ? 1 : 0);
$dental = mysql_real_escape_string($_POST['dental'] == 'dental' ? 1 : 0);
I also have a custom function that cleans the user input from the form:
function secure($string) {
$string = strip_tags($string);
$string = htmlspecialchars($string);
$string = trim($string);
$string = stripslashes($string);
$string = mysql_real_escape_string($string);
return $string;
}
How can I use a foreach command to post these variables and also have each variable passed through the secure() function, rather than reptitively typing out mysql_real_escape_string as shown above?
Thank you