title: Fix undefined index in PHP
body: <p>I am trying to get the option value from my select txtYear but I get error like undefined index. I don't know what I did wrong?</p>
  
  <pre><code>&lt;TR&gt;
      &lt;TH&gt;&lt;p style="color:red; width:150px"&gt;Year Level&lt;/p&gt;&lt;/TH&gt;
      &lt;TD&gt;
      &lt;SELECT NAME="txtYear" style="width:200px"&gt;
              &lt;OPTION VALUE="select any value"&gt;
              &lt;OPTION VALUE="First Year"&gt;First Year&lt;/OPTION&gt;
              &lt;OPTION VALUE="Second Year"&gt;Second Year&lt;/OPTION&gt;
              &lt;OPTION VALUE="Third Year"&gt;Third Year&lt;/OPTION&gt;
              &lt;OPTION VALUE="Fourth Year"&gt;Fourth Year&lt;/OPTION&gt;
              &lt;OPTION VALUE="Fifth Year"&gt;Fifth Year&lt;/OPTION&gt;
      &lt;/SELECT&gt;
      &lt;/TD&gt;
  &lt;/TR&gt;
  
  &lt;TR&gt;
      &lt;TH&gt;&lt;p style="color:red; width:150px"&gt;Section&lt;/p&gt;&lt;/TH&gt;
       &lt;TD&gt;
  &lt;SELECT NAME="txtSec" style="width:200px"&gt;
          &lt;OPTION VALUE="select any value"&gt;
          &lt;?php
              $year = $_POST['txtYear'];
  
              $con = mysqli_connect("localhost", "root", "", "scheduling");
              if (mysqli_connect_errno())
                  {echo "Failed to connect to MySQL: " . mysqli_connect_error();}
  
              if($year=="First Year"){
                  $sql="SELECT `Section` FROM `section` WHERE `Year`='First Year'";
                  $result = mysqli_query($con, $sql);
                  while($row = mysqli_fetch_array($result))
                  {    
                      echo '&lt;option value="'.$row['Section'].'"&gt;'.$row['Section'].'&lt;/option&gt;';
                  }
              }
          ?&gt;  
  &lt;/SELECT&gt;
          &lt;/TD&gt;
  &lt;/TR&gt;
  </code></pre>
  
  <p>What happens here is that when a user select first year from combo box year level, it will only display the section based on the year level from the database.</p>