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