• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

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.";
      }
}
}
?>
0
pingeyeg
Asked:
pingeyeg
1 Solution
 
RoonaanCommented:
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now