Hi
I'm trying to collect some information from the user regarding a complaint. In my form I have 3 select menus and a text box. I'm populating the 2nd menu depending on the 1st menu's choice.(The data is stored in a mysql database). When the user clicks submit the choice from the 2nd and 3rd select menus as well as the text should get stored in my database. However, I'm having a problem retrieving the value/ choice of the 2nd select menu when inserting the data into my database. This basically appears as a zero(0) in my database. I give below the code from 3 files which are related. Hope someone can help me out!
The file which gets the info from the user
<script type="text/javascript">
//Browser support code
<!--
//Get the HTTP Object
function getDept(str)
{
if(str=="")
{
document.getElementById("deptdiv").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("deptdiv").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","newcomp.php?group="+str,true);
xmlhttp.send();
}
//-->
</script>
</head>
<body>
<h3>Report Your Complaint Here</h3>
<form method="post" name="form1" action="savecomp.php">
<table>
<tr><td>Complaint related to</td><td> <select name="group" onchange="getDept(this.value)">
<option value="">Please Select</option>
<option value="1">Academic Department</option>
<option value="2">Professional Service Department</option></select></td></tr><br />
<tr><td>Please Select the Relevant Department</td><td><div id="deptdiv"><select name="dept">
<option>Select Department</option></select></div></td></tr><br />
<tr><td>Severity</td><td><select name="severity">
<option value="">Please Select</option>
<option value="1">Low</option>
<option value="2">Medium</option>
<option value="3">High</option></select></td></tr>
</table><br />
Please type in your complaint below<br />
<textarea name="complaint" rows="10" cols="50"></textarea><br />
<input type="submit" value="Submit"/>
</form>
</div>
</div>
<div id="footer"> Varne Somasundaram <br /></div>
</div>
</body>
</html>
The file that processes the ajax request to populate the 2nd select menu
<?php
$group=$_GET["group"];
$link = mysql_connect('localhost', 'root', '-----');
if(!$link)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("complaint_sys", $link);
$sql="SELECT dept_name FROM department WHERE group_id = '".$group."'";
$result = mysql_query($sql);
echo "<table>";
echo "<tr><td>";
echo "<select name=\"dept\" onchange=\"saveDept(this.value)\">";
echo "<option>Please Select</option>";
while($row = mysql_fetch_array($result))
{
echo "<option value=" . $row['dept_id'] . ">".$row['dept_name'] . "</option>";
}
echo "</select>";
echo "</td></tr>";
echo "</table>";
?>
The file that does the inseting of form data into the database
<h3>Thank You</h3>
<?php
mysql_connect("localhost", "root", "-----") or die ('Error: '.mysql_error());
mysql_select_db("complaint_sys");
$query="INSERT INTO complaint(date, created_by, description, severity_id, assigned_to, dept_id, status_id)VALUES (Now(), '1','$_POST[complaint]' , '$_POST[severity]', '1', '$_POST[dept]', '1')";
mysql_query($query) or die('Error updating database');
echo "Database Updated With complaint";
?>
</div>
</div>
</div>
</body>
</html>