title: Checking seat numbers correctly in MySql table
body: <p>I am developing a script for a table called 'minivan'. Here is the table structure  <a href="http://sqlfiddle.com/#!2/fe4932/1" rel="nofollow">sql fiddle link</a>. Admin provides seats for minivan.</p>
  
  <p>I want to check if seats are available from this search form: <a href="https://dl.dropboxusercontent.com/u/248874458/Admin/searchform/search.html" rel="nofollow">search form link</a> The method is GET.</p>
  
  <p>First i want to check the date [this is format of date: 2015-02-16 for example] that a user submits. If the date matches i want to proceed with 'from' and 'to' location that a user chooses. If records are found i want to check what is the total passenger from the dropdown list for different ages that a users provides.</p>
  
  <p>If the total number of passenger does not exceed the seat number for a particular day that a user chooses, i want to echo "seats are available". and proceed with other parts that i am planning to develop later. </p>
  
  <pre><code>&lt;?php
        $servername = "localhost";
      $username = "root";
     $password = "";
     $dbname = "test";
  
    // Create connection
      $conn = new mysqli($servername, $username, $password, $dbname);
      // Check connection
    if (!$conn) {
  die("Connection failed: " . $conn-&gt;connect_error);
   }
  if (isset($_GET['submit'])) {
  
  $date = $_GET['date_up'];
  
  
  $query = "SELECT date_up FROM minivan WHERE date_up = '$date'";
  
  $result = mysqli_query($conn, $query);
  
  $numrows = mysqli_num_rows($result);
  //print_r($numrows);
  
      if ($numrows)
      {
          $startPlace = $_GET['startpoint'];
  
  
          $query2 = "SELECT startpoint FROM minivan WHERE startpoint = '$startPlace'";
  
          $result2 = mysqli_query($conn, $query2);
          //print_r($result2);
          $numrows2 = mysqli_num_rows($result2);
  
          $endPlace = $_GET['endpoint'];
  
          $query3 = "SELECT endpoint FROM minivan WHERE endpoint = '$endPlace'";
  
          $result3 = mysqli_query($conn, $query3);
              //print_r($result2);
          $numrows3 = mysqli_num_rows($result3);
  
              if ($numrows2 &amp;&amp; $numrows3) {
                  $adult = $_GET['adult'];
                  $juvenile = $_GET['juvenile'];
                  $kids = $_GET['kids'];
                  $child = $_GET['child'];
                  $totalPassenger = $adult + $juvenile + $kids + $child ;
  
                  $seatQuery = "SELECT seat FROM minivan WHERE seat &gt; $totalPassenger";
  
                  $result4 = mysqli_query($conn, $seatQuery);
  
                  $numrows4 = mysqli_num_rows($result4);//shows error here how to fix it?
                  if ($numrows4) {
                       while ($row = mysqli_fetch_row($result4)) {
                      $seats = $row[0];
                      echo "$seats are availble for the $date you selected";
                      }
                  } else {
                      echo "no seats are found";
                  }
              } 
  } else {
      "start point and end point does not match";
      }
  
    }
  
  $conn-&gt;close();
     ?&gt;
  </code></pre>
  
  <p>It shows error here <strong>$numrows4 = mysqli_num_rows($result4);//shows error here how to fix it?</strong></p>
  
  <p>here is the form i am trying to search with</p>
  
  <pre><code>&lt;form action="" method="GET"&gt;
  &lt;a href=""&gt;From&lt;/a&gt;
  &lt;select name="startpoint" id="from"&gt;
      &lt;option &gt;Hat Yai Airport&lt;/option&gt;
      &lt;option &gt;Pak Bara&lt;/option&gt;
      &lt;option &gt;Kohlipe&lt;/option&gt;
  &lt;/select&gt;
  &lt;a href=""&gt;To&lt;/a&gt;
  &lt;select name="endpoint" id="to"&gt;
      &lt;option &gt;Pak Bara&lt;/option&gt;
      &lt;option &gt;Hat Yai Airport&lt;/option&gt;
      &lt;option &gt;Kohlipe&lt;/option&gt;
  &lt;/select&gt;
  &lt;label for="Date"&gt;Date&lt;/label&gt;
  &lt;input type="text" name="date_up" id="datepicker"&gt;
  &lt;h4 style="margin-top: 30px;"&gt;Passengers&lt;/h4&gt;
  &lt;a href=""&gt;Adults&lt;/a&gt;
  &lt;select name="adult" id="from"&gt;
      &lt;option &gt;1&lt;/option&gt;
      &lt;option &gt;2&lt;/option&gt;
      &lt;option &gt;3&lt;/option&gt;
      &lt;option &gt;4&lt;/option&gt;
      &lt;option &gt;5&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;a href=""&gt;&lt; 12 years&lt;/a&gt;
  &lt;select name="juvenile" id="to"&gt;
      &lt;option &gt;0&lt;/option&gt;
      &lt;option &gt;1&lt;/option&gt;
      &lt;option &gt;2&lt;/option&gt;
      &lt;option &gt;3&lt;/option&gt;
      &lt;option &gt;4&lt;/option&gt;
  &lt;/select&gt;
      &lt;a href=""&gt; &lt; 7 years&lt;/a&gt;
  &lt;select name="kids" id="from"&gt;
      &lt;option &gt;0&lt;/option&gt;
      &lt;option &gt;1&lt;/option&gt;
      &lt;option &gt;2&lt;/option&gt;
      &lt;option &gt;3&lt;/option&gt;
  &lt;/select&gt;
  &lt;a href=""&gt; &lt; 3 years&lt;/a&gt;
  &lt;select name="child" id="to"&gt;
      &lt;option &gt;0&lt;/option&gt;
      &lt;option &gt;1&lt;/option&gt;
      &lt;option &gt;2&lt;/option&gt;
      &lt;option &gt;3&lt;/option&gt;
  &lt;/select&gt;
  &lt;input type="submit" value="Search" class="submit" name="submit"&gt;
  </code></pre>
  
  <p>Can't really figure out whats wrong with this. I am beginner in php and mysql. Please help me solve this.</p>