Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filter_var in php 5.3.8

Tags:

php

I am developing a user registration form and want to validate a user's email address. However,all the php docs I have read suggest the use of filter_var. My script validates a valid email as invalid. Please post a working script or perhaps guide me through my script. Hers is my script :

     <?php
      if(isset($_POST['email'])== true && empty($_POST['email'])false)
      {
       $email = $_POST['email'];
      }
      if(filter_var($email,FILTER_VALIDATE_EMAIL)) 
      {
       echo"valid email";
      }
      else
      {
      echo"invalid email";
      }
     ?>
like image 590
Rick Menss Avatar asked Jul 08 '26 06:07

Rick Menss


1 Answers

if(isset($_POST['email'])== true && empty($_POST['email'])false)

this should be

if(isset($_POST['email']) && !empty($_POST['email']) )

or as @jack you can use just

if (!empty($_POST['email']))

the empty() does implicit isset()

like image 73
NullPoiиteя Avatar answered Jul 09 '26 21:07

NullPoiиteя



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!