Posted By

acosonic on 09/01/09


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Using PHP's filter_var to validate email or number

 / Published in: PHP

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


  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  

You need to login to post a comment.