title: Validate multiple empty fields in PHP
body: <p>I have the following statement for validating empty fields in PHP which works just fine: </p>
  
  <pre><code>if (isset($_SESSION['logged_in'])) {
  if (isset($_POST['room'], $_POST['area'])) {
      $room = $_POST['room'];
      $area = $_POST['area'];
  
      if (empty($room) or empty($area)) {
          $error = 'Required!';
      } else {
          $query = $pdo-&gt;prepare('INSERT INTO apartments (apartments_room, apartments_area) VALUES (?, ?)');
  
          $query-&gt;bindValue(1, $room);
          $query-&gt;bindValue(2, $area);
  
          $query-&gt;execute();
  
          header('Location: index.php');
  
      }
  }
  </code></pre>
  
  <p>I have now opened up for more columns in the database and therefor also more insert fields in the html to validate. My question is only how I formulate the if statement for the validation when checking for multiple empty fields in this case. </p>
  
  <p>So this code for example doesn't work anymore:</p>
  
  <pre><code>if (isset($_SESSION['logged_in'])) {
  if (isset($_POST['room'], $_POST['area'], $_POST['rent'], $_POST['address'], $_POST['floor'], $_POST['city'], $_POST['freeFromDate'])) {
      $room = $_POST['room'];
      $area = $_POST['area'];
      $rent = $_POST['rent'];
      $address = $_POST['address'];
      $floor = $_POST['floor'];
      $city = $_POST['city'];
      $freeFromDate = $_POST['freeFromDate'];
  
      if (empty($room) || empty($area) ||  empty($rent) ||  empty($address) ||  empty($floor) ||  empty($city) || empty($freeFromDate)) {
          $error = 'Required!';
      } else {
          $query = $pdo-&gt;prepare('INSERT INTO apartments (apartments_room, apartments_area, apartments_rent, apartments_address, apartments_floor, apartments_city, apartments_freeFromDate) VALUES (?, ?, ?, ?, ?, ?, ?)');
  
          $query-&gt;bindValue(1, $room);
          $query-&gt;bindValue(2, $area);
          $query-&gt;bindValue(3, $rent);
          $query-&gt;bindValue(4, $address);
          $query-&gt;bindValue(5, $floor);
          $query-&gt;bindValue(6, $city);
          $query-&gt;bindValue(7, $freeFromDate);
  
          $query-&gt;execute();
  
          header('Location: index.php');
  
      }
  }
  </code></pre>
  
  <p>How to formulate the syntax here?</p>
  
  <p>Thanks!</p>