title: Undefined index error(subject_code and course_code) in php
body: <p>I am currently working in php. in the below code i got undefined index: subject_code at line 42 and undefined index : course_code at line 24. so anyone help me.
  i tried to remove the error but i can't .so anyone help me.</p>
  
  <pre><code>        &lt;script language="javascript"&gt;
          function changeSelection(value){
  
             var length = document.getElementById("hai3").options.length;
  
           if(value == 0){
            for(var i = 1;i&lt;length;i++)
          document.getElementById("hai3").options[i].selected = "selected";
  
              document.getElementById("hai3").options[0].selected = "";
            }
  
            }
           &lt;/script&gt;
            &lt;script language="javascript"&gt;
                function check(elem) {
          document.getElementById('dis').disabled = !elem.selectedIndex;
            }
            &lt;/script&gt;
            &lt;?php
                 mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());
             mysql_select_db("slseatapp") or die(mysql_error());
  
            if($_POST['course_code']){
        @$exam_name=$_POST['course_code'];
            ?&gt;
  
           &lt;B&gt;SELECT COURSE CODE&lt;/B&gt; &lt;select name="hai2" id="hai2"&gt;
              &lt;option&gt;Select&lt;/option&gt;
              &lt;?php
  
          $query="SELECT distinct course_code FROM examcourse where exam_name = '$exam_name' ";
  
               $result = mysql_query($query);
            while($nt=mysql_fetch_array($result)) {
            echo "&lt;option value='".$nt['course_code']."'&gt;".$nt['course_code']."&lt;/option&gt;";
                   }
                    ?&gt;
  
                  &lt;/select&gt;
                   &lt;?php }
                if($_POST['subject_code']){
                @$subject_code=$_POST['subject_code'];
              ?&gt;
               &lt;B&gt;SELECT SUBJECT CODE&lt;/B&gt;
             &lt;select name="hai3[]"  id="hai3" multiple="multiple" onChange="changeSelection(this.value),check(this);"&gt;
      &lt;option value="0"&gt;Select All&lt;/option&gt;
       &lt;?php
  
          $query="SELECT distinct subject_code FROM coursesubject where course_code = '".$subject_code."' ";
          $result = mysql_query($query);
          while($nt=mysql_fetch_array($result)) {
          echo "&lt;option value='".$nt['subject_code']."'&gt;".$nt['subject_code']."&lt;/option&gt;";
          }
      ?&gt;
         &lt;/select&gt;
  
            &lt;?php }?&gt;
  </code></pre>