Not all fields are being checked

I have a php file that checks to make sure every field was filled out, but for some reason the only field that gets displayed on the screen is the strComments field.  Why would all the rest be bypassed?

<?php
if($_SERVER['REQUEST_METHOD'] == "POST")
{
      $strFirstname = $_POST['strFirstname'];
      $strLastname = $_POST['strLastname'];
      $strCompany = $_POST['strCompany'];
      $strEmail = $_POST['strEmail'];
      $strPhone = $_POST['strPhone'];
      $strComments = $_POST['strComments'];
      
      if(empty($strFirstname))
      {
            $result = "Please enter your <b>Firstname</b>.<br>";
      } else {
            $strFirstname = $_POST['strFirstname'];
      }
      
      if(empty($strLastname))
      {
            $result = "Please enter your <b>Lastname</b>.<br>";
      } else {
            $strLastname = $_POST['strLastname'];
      }
      
      if(empty($strEmail))
      {
            $result = "Please enter your <b>Email</b>.<br>";
      } else {
            $strEmail = $_POST['strEmail'];
      }
      
      if(empty($strPhone))
      {
            $result = "Please enter your <b>Phone #</b>.<br>";
      } else {
            $strPhone = $_POST['strPhone'];
      }
      
      if(empty($strComments))
      {
            $result = "Please enter your <b>Comments</b>.<br>";
      } else {
            $strComments = $_POST['strComments'];
      }
      
if(empty($strFirstname) == false && empty($strLastname) == false && empty($strEmail) == false && empty($strPhone) == false && empty($strComments) == false)
{
      $to = 'brannon@brannongloverdesigns.com';
      $subject = 'Comments/Requests';
      $message = "First Name: $strFirstname\r\n Last Name: $strLastname\r\n Company: $strCompany\r\n Email: $strEmail\r\n Phone: $strPhone\r\n Comments: $strComments\r\n";
      $headers = 'From: Contact Us Form' . '\r\n';
      
      if(mail($to, $subject, $message, $headers))
      {
            $result = "Thank you very much for your interest in us!  We will be in touch very soon!";
      } else {
            echo "Mail sending errors.  Please contact the webmaster.";
      }
}
}
?>
LVL 1
pingeyegAsked:
Who is Participating?
 
RoonaanConnect With a Mentor Commented:
I think you intended to use $results .= instead of $results = ?

-r-
0
 
RightNLCommented:
yep .. Roonaan is right..

it will check all errors but since the result variable  is overwritten each time it will only display the last error.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.