-1
我有這樣的文件結構。PHP的AJAX - 沒有得到價值表格提交
當我提出,我得到了一個錯誤:
Notice: Undefined index: course1 in C:\wamp\www\mysite\formprocess2.php on line 7
Notice: Undefined index: course2 in C:\wamp\www\mysite\formprocess2.php on line 8
Notice: Undefined index: course3 in C:\wamp\www\mysite\formprocess2.php on line 9
我不明白爲什麼會這樣。
這裏是我的代碼:
的index.php:
<html>
<head>
<script>
function showUser(str) {
if (str=="") {
document.getElementById("course").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("course").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getcourse2.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<table width="850" border="1" align="center" >
<form action="formprocess2.php" method="POST" name="applicationform" id="applicationform">
<tr><td> <p>Application Form</p></td></tr>
<tr><td colspan="3">Name of the College where admission is sought :</td>
<td colspan="3"><select name="college" id="college" onchange="showUser(this.value)">
<option value="">----Select College----</option>
<?php
include("db_connect.php");
$select=mysql_query("select * from college");
while($data=mysql_fetch_array($select))
{
?>
<option value="<?php echo $data['ID'];?>"><?php echo $data['collegename'];?></option>
<?php
}
?>
</select></td>
</tr>
<tr>
<td colspan="3">Name of the Course applied for : </td>
<td colspan="3" id="course"></td>
</tr>
<tr>
<td colspan="3"><input type="submit" name="submit" id="submit" value="Submit"></td>
<td colspan="3"> </td>
</tr>
</form>
</table>
</body>
</head>
</html>
getcourse2.php:
<?php include('db_connect.php'); ?>
<?php
for ($x=1; $x<4; $x++) {
$course="course"."$x";
?>
<select name="<?php echo $course?>"id="<?php echo $course?>">
<?php
$q = intval($_GET['q']);
$sql = "SELECT course.coursename FROM course
INNER JOIN college
ON college.ID=course.collegeID WHERE college.ID ='$q'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
?>
<option value="<?php echo $row['coursename'];?>"><?php echo $row['coursename'];?></option>
<?php
}
?>
</select>
<?php
}?>
formprocess2.php:
<?php
echo $college= $_POST["college"];
echo $course1= $_GET["course1"];
echo $course2=$_GET["course2"];
echo $course3= $_GET["course3"];
?>
發生了什麼事錯在這裏,我該如何修復它?
我花了第二弄清楚究竟是怎麼回事,他的代碼,這個答案是正確的...雖然html中還有一個額外的''標籤。 –
是的,它的工作,當然。所有字段的POST方法。所以應該有一個$ _POST數組。 OP,請在