I can get VALIDATE to work, but SANITIZE is sending me crazy. I test it with an unacceptable email address but it enters the address into the database table warts and all. Please can you spot what I am doing wrong?
if (isset($_POST['email'])) {
$etrim = trim($_POST['email']);
}
if (filter_var($etrim, FILTER_SANITIZE_EMAIL)) {
$e = mysqli_real_escape_string($dbcon, $etrim);
}else{
$errors[] = 'You forgot to enter your email address.';
}
the SANITIZE filters return the sanitised values. You're not using the sanitised value, only checking that it exists. You're still using the original value.
Also note that, in my opinion, using the SANITIZE filter for e-mail addresses makes absolutely no sense. When a user gives you his/her e-mail address, it's either the exact address or it's an incorrect one. "Sanitising" the address given by potentially removing one or more characters means you're no longer using the address the user specified, so why should you expect messages sent to that newly created address to reach the user?
I completely agree bradgrafelman, my original question was entirely academic, ie how to make sanitization work. unfortunately I chose a poor example.
Thanks for your prompt comment
Bookmarks