I want to be able to create a foreach loop that will go through all the intended POST variables and then assign it as a standard variable. For example, I want to have $username = $_POST['username'] without even knowing username exists in the context of the foreach loop.
$form_elements = array("username","firstname","lastname","email","country","zipcode","gender","dob_y","dob_m","dob_d","password1","password2");
foreach ($form_elements as $element) {
if ( !(isset($_POST[$element])) || (empty($_POST[$element])) ) {
$error_msg = "All fields must be filled in.";
return false;
} else {
$($element} = mysql_escape_string($_POST[$element]); // is this how I do it
}
}
This will help in sanitizing the data and seperating it from the initially submitted POST variables. Any insight would be very appreciated.