Before submitting form data into a database (MySQL), what should be done? adding slashes, correct?
Say at the beginning of the script I declare variables that contain the form input:
$var = $_POST['x'];
$two = $_POST['x2'];
Now if I wanted to add slashes right before inserting, I'd do this:
foreach ($_POST as $key=>$value)
{
$_POST[$key] = htmlspecialchars(addslashes(trim($value)));
}
Would that still be effective if I do:
"INSERT INTO <table> (field1, field2) VALUES ('$var', '$two')";
Instead of:
"INSERT INTO <table> (field1, field2) VALUES ('$_POST['x']', '$_POST['x2']')";