0

在这段代码中,我想选择考试,它应该反映相应考试的课程代码,当我选择考试名称时,它不会填充另一个下拉列表,所以请任何人帮助我。

上传1_view.php

<script type="text/javascript" charset="utf-8">
  <script type="text/javascript" src="http://ajax.googleapis.com/
    ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script type="text/javascript">
  $(document).ready(function()
   {
   $(".hai").change(function()
     {
    var id=$(this).val();
  var dataString = 'course_code='+ course_code;

   $.ajax
    ({
    type: "POST",
     url: "upload2_view.php",
  data: dataString,
      cache: false,
    success: function(html)
   {
  $(".hai2").html(html);
   } 
   });

  });
    });
</script></script>
</head>
<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  File to import:<br />
  <input size='30' type='file' name='filename'>
  Select Exam name:<select name=hai class="hai">
  <?php
    mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());

        mysql_select_db("slseatapp") or die(mysql_error());

      $query="select  distinct exam_name from examcourse";
    $result = mysql_query($query);
    while($nt=mysql_fetch_array($result)) {
    echo "<option value='".$nt['exam_name']."'>".$nt['exam_name']."</option>";
     }
    ?>
  </select>
  <input type="submit" name="submit" value="Upload">
</form>
<?php 
  mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());

  mysql_select_db("slseatapp") or die(mysql_error());

  //Upload File 
  if (isset($_POST['submit'])) { 
  if (is_uploaded_file($_FILES['filename']['tmp_name'])) { 




  //Import uploaded file to Database 
  $row = 1; 
  $handle = fopen($_FILES['filename']['tmp_name'], "r"); 
  $var = $_POST['hai'];
  $var1 = $_POST['hai2'];




  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { 

    //Update Database Values 

  $import="insert into student_table (id,register_number,name,course_code,subject_code,exam_name) VALUES('".mysql_real_escape_string($data[0])."', '".mysql_real_escape_string($data[1])."','".mysql_real_escape_string($data[2])."','$var','$var1','$var2')"; 
  $import="replace into  student_table (id,register_number,name,course_code,subject_code,exam_name) VALUES('".mysql_real_escape_string($data[0])."', '".mysql_real_escape_string($data[1])."','".mysql_real_escape_string($data[2])."','$var','$var1','$var2')";


  mysql_query($import) or die(mysql_error()); 


  } 


  }
     fclose($handle); 
  echo"<script>alert('Uploaded Successfully');</script>";

   } 
  ?>
<br />

2.上传2_view.php

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
File to import:<br />
Course code:<select name=hai2 class="hai2">
<?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>
4

1 回答 1

0

请更改以下错误:

删除第一个脚本标签。不要删除该脚本标签之间的代码

<script type="text/javascript" charset="utf-8">

</script>

请找到 course_code,没有找到 course_code
它会 -

var dataString = 'course_code='+ id;

添加一个要显示第二个下拉列表的跨度标签:

<span class="hai2">

</span>

在第二个下拉列表中删除 class="hai2"

Course code:<select name="hai2">

Upload1_view.php 应该是 upload2_view.php

完整代码:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
   <script type="text/javascript">
    $(document).ready(function()
     {
     $(".hai").change(function()
       {
      var id=$(this).val();
      // Please find the course_code, course_code was not found
   var dataString = 'course_code='+ id;

     $.ajax
      ({
      type: "POST",
       url: "upload2_view.php",
    data: dataString,
        cache: false,
      success: function(html)
     {
   $(".hai2").html(html);
     } 
     });

   });
      });
</script>
 </head>



   <form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

    File to import:<br />

 <input size='30' type='file' name='filename'>

   Select Exam name:<select name=hai class="hai">

      <?php
   mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());

       mysql_select_db("slseatapp") or die(mysql_error());

     $query="select  distinct exam_name from examcourse";
  $result = mysql_query($query);
  while($nt=mysql_fetch_array($result)) {
 echo "<option value='".$nt['exam_name']."'>".$nt['exam_name']."</option>";
    }
   ?>
  </select>
  <!--PLEASE DEFINE WHERE YOU WANT PUT YOUR SECOND DROPDOWN-->
  <span class="hai2">

  </span>

<input type="submit" name="submit" value="Upload"></form>



 <?php 

    mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());

  mysql_select_db("slseatapp") or die(mysql_error());

//Upload File 
 if (isset($_POST['submit'])) { 
 if (is_uploaded_file($_FILES['filename']['tmp_name'])) { 




//Import uploaded file to Database 
$row = 1; 
$handle = fopen($_FILES['filename']['tmp_name'], "r"); 
    $var = $_POST['hai'];
  $var1 = $_POST['hai2'];




while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { 

      //Update Database Values 

   $import="insert into student_table (id,register_number,name,course_code,subject_code,exam_name) VALUES('".mysql_real_escape_string($data[0])."', '".mysql_real_escape_string($data[1])."','".mysql_real_escape_string($data[2])."','$var','$var1','$var2')"; 
   $import="replace into  student_table (id,register_number,name,course_code,subject_code,exam_name) VALUES('".mysql_real_escape_string($data[0])."', '".mysql_real_escape_string($data[1])."','".mysql_real_escape_string($data[2])."','$var','$var1','$var2')";


 mysql_query($import) or die(mysql_error()); 
} 
}
fclose($handle); 
echo"<script>alert('Uploaded Successfully');</script>";

     } 
?>


2.upload_view2.php

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

  File to import:<br />


Course code:<select name="hai2">
    <?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>
于 2013-08-07T09:35:02.467 回答