Hi,
I new to PHP and am waorking on creating an electives database with a web front end using WAMP. As the code below shows, I have created a form that can be used to view data from one table (course) and then insert the user's inputs into another table called suggested. My problem is not with getting values from course table into the combo box....the courseID values are showing in the combo box. My problem is with the inserting of the selected option (courseID) into the second table called suggested...The insert only puts modID, modname and proposer from the input text fields but not courseID from the combo box field. Please is there any help with this...I am so stuck for some days now...Thanks
Code:
<html>
<head>
<title>Suggest electives for a selected cohort</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form method="post">
<table width="600" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Course Code</td>
<td>
<SELECT NAME='selcosID' ID='selcosID'>
<?php
include 'config.php';
include 'opendb.php';
$query = "SELECT * FROM course";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "<OPTION VALUE=".$row['selcosID'].">".$row['CourseID']."</OPTION>";
}
?>
</SELECT>
</td>
</tr>
<tr>
<td width="100">Cohort</td>
<td>
<SELECT NAME='selcohort'ID='selcohort'>
<?php
include 'config.php';
include 'opendb.php';
$query = "SELECT Cohort FROM course";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "<OPTION VALUE=".$row['cohid'].">".$row['Cohort']."</OPTION>";
}
?>
</SELECT>
</td>
</tr>
<tr>
<td width="100">Module Code</td>
<td><input name="modID" type="text" id="modID"></td>
</tr>
<tr>
<td width="100">Module Name</td>
<td><input name="modName" type="text" id="modName"></td>
</tr>
<tr>
<td width="100">Proposer</td>
<td><input name="prop" type="text" id="prop"></td>
</tr>
<tr>
<td width="100"> </td>
<td><input name="submit1" type="submit" id="submit1" value="Submit Your Suggestion"></td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit1']))
{
include 'config.php';
include 'opendb.php';
$selcosID = $_POST['selcosID'];
$selcohort = $_POST['selcohort'];
$modID = $_POST['modID'];
$modName = $_POST['modName'];
$prop = $_POST['prop'];
// prepare the query strings
$query = "INSERT INTO suggested (CourseID, Cohort, ModuleID, ModuleName, Proposer) VALUES ('$selcosID', '$selcohort', '$modID','$modName', '$prop')";
mysql_query($query) or die(mysql_error());
include 'closedb.php';
echo "Your suggestion has been successfully submitted";
}
?>
</body>
</html>