Q: How to make sure all fields are filled in php? 
Hi.
I am trying to write some php to export input to csv format. It works really well, except it doesn't check to make sure all fields are filled. How can I make sure they are all filled.
<?php
$txt = "report.csv";
$fh = fopen($txt, 'a+');
if (isset($_POST['firstname']) && isset($_POST['lastname']) && isset($_POST['version']) && isset($_POST['description'])) { // check if both fields are set
   $first = $_POST['firstname'];
   $last =  $_POST['lastname'];
   $version = $_POST['version'];
   $description = $_POST['description'];
   $q = "\"";
   $c = ",";
   $check=$first.$last.$version.$descrption;
   $txt=$q.$first.$q.$c.$q.$last.$q.$c.$q.$version.$q.$c.$q.$description.$q;
   if (strpos($check, '"') !== false){
   echo file_get_contents("/quotes.html");
   } else {
   file_put_contents('report.csv',$txt."\n",FILE_APPEND); // log to data.txt
   echo file_get_contents("yay.html");
   exit();
   }
} else {
echo file_get_contents("notfilled.html");
}

?>

HTML
  <form action="problem.php" method="POST">
    <label for="fname"><h3>First Name</h3></label>
    <input type="text" id="fname" name="firstname">

    <label for="lname"><h3>Last Name</h3></label>
    <input type="text" id="lname" name="lastname">
    <label for="version"><h3>Version</h3></label>
    <select id="version" name="version">
      <option value="0.1">0.1</option>
      <option value="0.2">0.2</option>
      <option value="Other">Other</option>
    </select>
    <label for="description"><h3>Description</h3></br><p1>Please describe your problem with details. Explain what the problem is how to reproduce it.</label>
    <textarea id="description" name="description" style="height:100px"></textarea>

    <input type="submit" value="Submit">
  </form>


A: You need to add !empty to check the values are empty or not.
if you want to check for other case too such as name should not be number the you should use regex too.
if (!empty($_POST['firstname']) && !empty($_POST['lastname']) && !empty($_POST['version']) && !empty($_POST['description'])) {
For you comment Whats the difference from !empty and isset?
Suppose you have a variable
$test= "";

if(empty($test)) // it return true because "" is empty

if(isset($test)) // return true because $test is defined 

while
if(empty($anotherTest)) // return true because its null

if(isset($anotherTest)) // return false because is not defined

