title: How to filter records by date with PHP
body: <p>I have a working date filter with PHP. The problem is that if I don't filter my records then no records are shown and also I get this type of error: </p>
  
  <blockquote>
    <p>Notice: Undefined index: dateFrom in ... on line 37</p>
  </blockquote>
  
  <p>How can I make a date filter using PHP, so that if I don't add any dates to my filter it shows all records, and if I add dates to filter it shows only filtered records?</p>
  
  <p>Here's my code:</p>
  
  <p><strong>HTML FORM</strong>
  <a href="https://i.stack.imgur.com/s6BtF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s6BtF.png" alt="enter image description here"></a></p>
  
  <pre><code>&lt;?php
      include('config/connect.php');
      $query=mysqli_query($connect,"SELECT * FROM tasks");
  ?&gt;
  
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Title&lt;/th&gt;
          &lt;th&gt;Due Date&lt;/th&gt;
          &lt;th&gt;Edit | View&lt;/th&gt;
      &lt;/tr&gt;
  
      &lt;?php
  
      //GETTING VALUE FROM FILTER
      $new_date = date('Y-m-d', strtotime($_POST['dateFrom']));
      //echo $new_date;
  
      $new_date2 = date('Y-m-d', strtotime($_POST['dateTo']));
      //echo $new_date2;
  
      $dateFrom = date('Y-m-d', strtotime($_POST['dateFrom']));
      $dateTo = date('Y-m-d', strtotime($_POST['dateTo']));
  
      while($row=mysqli_fetch_array($query)){
  
      //FILTERING USING DATES
      if (($row['due_date'] &gt; $dateFrom) &amp;&amp; ($row['due_date'] &lt; $dateTo)){
      ?&gt;
  
      &lt;tr&gt;
          &lt;td&gt;&lt;?php echo  $row['title'] ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo  $row['due_date'] ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;a href="edit_task.php?id=&lt;?php echo $row['id'];?&gt;"&gt; &lt;button type="button"&gt;Edit&lt;/button&gt; &lt;/a&gt; | &lt;a href="view_task.php?id=&lt;?php echo $row['id'];?&gt;"&gt; &lt;button type="button"&gt;View&lt;/button&gt; &lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;?php }} ?&gt;
  
  &lt;/table&gt;
  </code></pre>