title: php dropdownlist undefined index
body: <p>I'm a newbie to PHP programming and I am in the module of using dropdown list.</p>
  
  <blockquote>
    <p>A PHP Error was encountered Severity: Notice Message: Undefined index: yos.</p>
  </blockquote>
  
  <p>here's the code. I hope somebody help me. </p>
  
  <pre><code>&lt;?php
  
  $servername="localhost";
  $username="root";
  $password="";
  $dbname="online_voting_web";
  //Create connection
  $con=mysqli_connect($servername,$username,$password,$dbname);
  
  $name       = $_POST['firstname'];
  $name2      = $_POST['lastname'];
  $name3      = $_POST['middlename'];
  $username       = $_POST['username'];
  $pass       = md5($_POST['password']);
  $yos = isset($_POST['yos']) ? $_POST['yos'] : '';
  $id         = $_POST['stud_id'];
  
  
  if(!$name || !$name2 ||$name3 || $id || !$year || !$pass|| !$username){
  $error="Please fill empty fields";
  include"student_reg.php";
  exit();
  }
  $sql = "SELECT stud_id FROM stud_name WHERE stud_id='$id'";
  $query = mysqli_query($con,$sql)or die(mysqli_error($con));
  $exist = mysqli_num_rows($query);
  
      if($exist==1){
      $nam="&lt;center&gt;&lt;h4&gt;&lt;font color='#FF0000'&gt;The student ID already   exist,register another&lt;/h4&gt;&lt;/center&gt;&lt;/font&gt;";
      unset($id);
      include('student_reg.php');
      exit();
  }
  $sql = "SELECT stud_username FROM stud_user WHERE     username='".$_POST['username']."'";
  $query = mysqli_query($con,$sql)or die(mysqli_error($con));
  $exist = mysqli_num_rows($query);
  
      if($exist==1){
      $nam="&lt;center&gt;&lt;h4&gt;&lt;font color='#FF0000'&gt;The student ID already exist,register another&lt;/h4&gt;&lt;/center&gt;&lt;/font&gt;";
      unset($id);
      include('student_reg.php');
      exit();
  
      }
  
  $sql = "INSERT INTO stud_name(stud_id,studFname,stud_Lname,stud_Mname)
       VALUES('$id','$name','$name2','$name3')";
  $sql2 = "INSERT INTO stud_course(stud_username,stud_year)
       VALUES('$username','$year')";
  $sql3 = "INSERT INTO stud_user(stud_id,stud_username)
       VALUES('$id','$username')"; 
  $sql4 = "INSERT INTO login_(username,password)
       VALUES('$username','$pass')";           
  
    $result = mysqli_query($con,$sql);
     $result2 = mysqli_query($con,$sql2);
   $result3 = mysqli_query($con,$sql3);
   $result4 = mysqli_query($con,$sql4);
  
  if(!$result &amp;&amp; !$result2 &amp;&amp; !$result3 &amp;&amp;!$result4){
  die("Error on mysql query".mysqli_error());
  }
  else{
  header("location: index.php");
  }
  
  ?&gt;
  </code></pre>
  
  <p>And this is the part of the code from another form where I first use the word yos</p>
  
  <pre><code>   &lt;!--Style link--&gt;
  &lt;link href="layout/styles/layout.css" rel="stylesheet" type="text/css"&gt;
  &lt;!--Navigation--&gt;
   &lt;/div&gt;
  &lt;/div&gt;
  &lt;body id="top"&gt;
  &lt;div class="wrapper row3"&gt;
  &lt;div class="rounded"&gt;
  &lt;main class="container clear"&gt; 
    &lt;div class="group btmspace-30"&gt; 
  
      &lt;div id="register"&gt;
  &lt;!--End of Navigation--&gt;
      &lt;fieldset&gt;
          &lt;legend&gt;&lt;h3&gt;Student Registration Form&lt;/h3&gt;&lt;/legend&gt;
    &lt;h4 style="color:#e60808;"&gt;
   &lt;?php global $nam; echo $nam;?&gt; &lt;/h4&gt; 
   &lt;?php global $error; echo $error;?&gt;                  
          &lt;!-- the login form--&gt;
  &lt;form enctype="application/x-www-form-urlencoded" action="" method="post" id="myform"&gt;
              &lt;div class="register"&gt;
              &lt;table width="400px"&gt;
   &lt;tr&gt;&lt;td&gt;&lt;label&gt;Firstname&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="firstname" value="" style="width:250px;    height:34px; border:1px solid #336666;"/&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;&lt;td&gt;&lt;label&gt;Middlename&lt;/label&gt;&lt;/td&gt;
   &lt;td&gt;&lt;input type="text" name="middlename" value="" style="width:250px; height:34px; border:1px solid #336666;"/&gt;&lt;/td&gt;
  &lt;tr&gt;&lt;td&gt;&lt;label&gt;Lastname&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="lastname" value="" style="width:250px; height:34px; border:1px solid #336666;"/&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;&lt;td&gt;&lt;label&gt;Username&lt;/label&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input type="text" name="username" value="" style="width:250px; height:34px; border:1px solid #336666;"/&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;&lt;td&gt;&lt;label&gt;Password&lt;/label&gt;&lt;/td&gt;
    &lt;td&gt;&lt;input type="password" name="password" value="" style="width:250px; height:34px; border:1px solid #336666;"/&gt;&lt;/td&gt;
  &lt;/tr&gt;
   &lt;tr&gt;
   &lt;td&gt;&lt;label&gt;Year Level&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;select name="yos" id="yos" style="width:250px; height:34px; border:1px solid #336666;"&gt;
  &lt;option value="000"&gt;Choose Level&lt;/option&gt;
  &lt;option value="G7"&gt;Grade 7&lt;/option&gt;
  &lt;option value="G8"&gt;Grade 8&lt;/option&gt;
  &lt;option value="G9"&gt;Grade 9&lt;/option&gt;
  &lt;option value="G10"&gt;Grade 10&lt;/option&gt;
  &lt;option value="G11a"&gt;Grade 11-GAS&lt;/option&gt;
  &lt;option value="G11b"&gt;Grade 11-Blhablha&lt;/option&gt;
  &lt;option value="G12a"&gt;Grade 12-Blahblah&lt;/option&gt;
  &lt;option value="G12b"&gt;Grade 12-khfakhf&lt;/option&gt;
  &lt;/select&gt;&lt;/td&gt;
   &lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;label&gt;ID Number&lt;/label&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input type="text" name="stud_id" value="" style="width:250px; height:34px; border:1px solid #336666;"/&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr&gt;&lt;td colspan="2" align="center"&gt;&lt;input type="submit" name="submit" value="Submit" style="width:100px; height:34px; border:1px solid #336666; border-radius:4px;"&gt;&lt;/td&gt;&lt;/tr&gt;
               &lt;/table&gt;
              &lt;/div&gt;
   &lt;/form&gt;
   &lt;script type="text/javascript"&gt;
  var frmvalidator = new Validator("myform"); 
  frmvalidator.addValidation("firstname","req","Please enter student     firstname"); 
   frmvalidator.addValidation("firstname","maxlen=50");
      frmvalidator.addValidation("middlename","req","Please enter student   middlename"); 
    frmvalidator.addValidation("middlename","maxlen=50");
      frmvalidator.addValidation("lastname","req","Please enter student middlename"); 
     frmvalidator.addValidation("lastname","maxlen=50");
      frmvalidator.addValidation("username","req","Please enter student username"); 
     frmvalidator.addValidation("username","maxlen=50");
     frmvalidator.addValidation("password","req","Please enter student password"); 
     frmvalidator.addValidation("password","minlen=6","Password must not be less than 6 characters.");
      frmvalidator.addValidation("year","req","Please enter student year"); 
     frmvalidator.addValidation("year","dontselect=000","You don't select year");
     frmvalidator.addValidation("stud_id","req","Please enter your ID number"); 
      frmvalidator.addValidation("stud_id","maxlen=50");
  
      &lt;/fieldset&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p>
     </p>