i want to know the error in this code

<?php

$firstname = $_POST    ['firstname'];
$lastname  = $_POST    ['lastname'];
$pass1     = md5($_POST['pass1']);
$pass2     = md5($_POST['pass2']);
$email     = $_POST    ['email'];

// filters name 
function filtername ($field) {
    $field = filter_var(trim($field), FILTER_SANITIZE_STRING);
    if (filter_var($field, FILTER_VALIDATE_REGEXP, array ("options"=> array ("regexp"=>"/^[Z-zA-Z\s]+/")))) {
        return $field;
    } else {
        return FALSE;
    }
}

// filters pass1 
function filterpass ($field) {
    $field = array('min_range' => 8,);
    if ($field < $min_range) {
        echo "password is mine range";
        return FALSE;
    } else {
        return $field;
    }
}

// filters email 
function filteremail ($field) {
    $field = filter_var(trim($field), FILTER_SANITIZE_EMAIL);
    if (filter_var($field, FILTER_VALIDATE_EMAIL)) {
        return $field;
    } else {
        return FALSE;
    }
}

/*
 * empty valedate input
 * fistname
 * lastname
 * pass1
 * pass2
 * email
 */

 $Errname = $Errpassword = $Erremail = "";
 $name = $password = $Email ="";

 if ($_SERVER ["REQUEST_METHOD"] == "POST") {

     // empty name 1
     if (empty ($firstname)) {
        echo $Errname = "sorry the firstname is empty"."<br />";
     } else {
         $name = filtername($firstname);
         if ($name == FALSE) {
             echo $Errname = "OOPS the valedate is false"."<br />";
         }
     }

     // empty name 2
     if (empty ($lastname)) {
        echo $Errname = "sorry the last name is emty"."<br />";
     } else {
         $name = filtername($lastname);
         if ($name == FALSE) {
             echo $Errname = "OPPS the valdeate last name is false"."<br />";
         }
     }

     // empty pass 1
     if (empty ($pass1)) {
        echo  "sorry the password is empty"."<br />";
     } 


     // empty pass 2
     if (empty ($pass2)) {
        echo "sorry the password is empty"."<br />";
     } 


     // empty email
     if (empty ($email)) {
        echo $Erremail = "sorry the Email is empty"."<br />";
     } else {
         $Email = filteremail($email);
         if ($Email == FALSE) {
             echo $Erremail = "OOPS the valseate email is false"."<br />";
         }
     }

     // check pass1 & pass2
     if ($pass1 !== $pass2) {
        echo "sorry the pass1 != pass2 ";
     }

 }

?>

There seem to be no syntax errors. Why do you assume there is an error? Do you get any messages? Is the result not what you expected? What is different from what you expected?

I agree with Broj1, what are the error codes you are getting? As far as syntax errors I really only found one on line 97 you have !== where it is supposed to be !=. But becasue you can't use !== that may be giving you some fault.

Just a note @toxicandy: !== is also a valid syntax. In PHP you can use three comparison operators in place of two which means you want to compare both values and types. See this link. So line

if($pass1 !== $pass2)

essentially says: if $pass1 is not equal to $pass2 and/or $pass1 is not the of same type as $pass2 then...

Consider the following code:

$pass1 = 1234;
$pass2 = '1234';
if($pass1 !== $pass2) // returns true
if($pass1 != $pass2) // returns false

But form fields always return strings so above test is a bit pointless.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.