Using PHP's filter_var to validate email or number


/ Published in: PHP
Save to your folder(s)

This code generates SQL depending on semantic type of variable from user input.

php>5.2


Copy this code and paste it in your HTML
  1. //selecting user based on his personal ID number
  2. if(filter_var($var, FILTER_VALIDATE_INT)) $sql = "select * from user where JMBG='$var'";
  3. //selecting user based on his email
  4. else if(filter_var($var, FILTER_VALIDATE_EMAIL)) $sql = "select * from user where email='$var'";
  5. //selecting user based on his username
  6. else $sql = "select * from user where username='$var'";

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.