-1

I have file structure like this.

When I submit, I am getting an error:

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  

I can't understand why this is happening.

Here is my code:

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">&nbsp;</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"];
?>

What's going wrong here, and how can I fix it?

cf-
  • 8,598
  • 9
  • 36
  • 58
Nikhil
  • 3
  • 1

1 Answers1

1

You are trying to get data in $_GET array, but your form method is POST, so you have to do this:

<?php 



echo $college= $_POST["college"];
echo $course1= $_POST["course1"];
echo $course2=$_POST["course2"];
echo $course3= $_POST["course3"];

?>
Paul Denisevich
  • 2,329
  • 14
  • 19