SLASHING A POST ARRAY

Try this little chunk of code to do two things : (1) Slash an entire array, and (2) Create variables from your form's field names on your POST page.

foreach ($_POST as $key => $val) {
    $$key = addslashes($val);
}

Now, for example, if you have a field named "firstname" on your form and you post to the PHP processing page, this script will create a variable named "$firstname" in which you can use throughout the rest of the script. Saves some time, and it also slashes user input to reduce the risk of SQL injection.

Find this article helpful?

Consider becoming a fan of our Facebook page! The link is in our fan box on the left!