Nazmul
Nazmul

Reputation: 115

Form validation in php is not working properly

Can anyone tell me what wrong i am doing here ? Error shows only if the First name is blank, for the rest (e.g lastname/email/body) it's not working. EMail validation also not working.

$error = "";
if (empty($fanme)) {
    $error = "First name must not be empty !";
   }
elseif (empty($lname)) {
   $error = "Last name must not be empty !";
   }
elseif (empty($email)) {
   $error = "email must not be empty !";
   }
elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
   $error = "Invalid Email Address !";
   }
elseif (empty($body)) {
   $error = "Message field not be empty !";
   }
else {
  $msg = "ok";
  }
}
if (isset($error)) {
     echo "<span style='color:red'>$error</span>";
        }
if (isset($msg)) {
     echo "<span style='color:green'>$msg</span>";
    }

Upvotes: 0

Views: 38

Answers (1)

Martijn
Martijn

Reputation: 514

It looks like you misspelled "$fname" in line 2 of your code above.

Upvotes: 2

Related Questions