-1

我目前在 php 中工作。在下面的代码中,我得到了未定义的索引:第 42 行的 subject_code 和未定义的索引:第 24 行的 course_code。所以任何人都可以帮助我。我试图删除错误,但我不能。所以任何人都可以帮助我。

        <script language="javascript">
        function changeSelection(value){

           var length = document.getElementById("hai3").options.length;

         if(value == 0){
          for(var i = 1;i<length;i++)
        document.getElementById("hai3").options[i].selected = "selected";

            document.getElementById("hai3").options[0].selected = "";
          }

          }
         </script>
          <script language="javascript">
              function check(elem) {
        document.getElementById('dis').disabled = !elem.selectedIndex;
          }
          </script>
          <?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'];
          ?>

         <B>SELECT COURSE CODE</B> <select name="hai2" id="hai2">
            <option>Select</option>
            <?php

        $query="SELECT distinct course_code FROM examcourse where exam_name = '$exam_name' ";

             $result = mysql_query($query);
          while($nt=mysql_fetch_array($result)) {
          echo "<option value='".$nt['course_code']."'>".$nt['course_code']."</option>";
                 }
                  ?>

                </select>
                 <?php }
              if($_POST['subject_code']){
              @$subject_code=$_POST['subject_code'];
            ?>
             <B>SELECT SUBJECT CODE</B>
           <select name="hai3[]"  id="hai3" multiple="multiple" onChange="changeSelection(this.value),check(this);">
    <option value="0">Select All</option>
     <?php

        $query="SELECT distinct subject_code FROM coursesubject where course_code = '".$subject_code."' ";
        $result = mysql_query($query);
        while($nt=mysql_fetch_array($result)) {
        echo "<option value='".$nt['subject_code']."'>".$nt['subject_code']."</option>";
        }
    ?>
       </select>

          <?php }?>
4

2 回答 2

1

试试isset喜欢

if(isset($_POST['course_code'])){
     $exam_name=$_POST['course_code'];
}

if(isset($_POST['subject_code'])){
     $subject_code=$_POST['subject_code'];
}
于 2013-08-13T05:38:31.253 回答
0

您可以通过以下语法检查数组中是否存在键(在本例中为键 'course_code'): array_key_exists($key, $array);

在您的情况下,这将是:

if(array_key_exists('course_code', $_POST){
    @$exam_name=$_POST['course_code'];
}
于 2013-08-13T05:47:22.063 回答