Im a newbie in php so i hope i can get some help regarding my problem. I have several input text and 3 drop down box where each of this drop down box are from different table. I need to insert all the data that the user select into 1 table and if possible the insertation of the data is done in the same page. It seems that the data from the input text can be inserted in to db while the data from drop down is empty in the db. 🙁 Below are my coding:
<?
if (!isset($_POST['insert'])) {
?>
<table>
<td class="style8">Workgroup</td>
<td><?
$res = $va;
$res = mysql_query("SELECT workingid FROM tblworkgroup")
or die("Invalid query: " . mysql_query());
//echo '<label>Select value:</label>';
echo '<select id="val" name="val" class=style8>';
echo '<option value="">-- Select One --</option>';
while ($row = mysql_fetch_assoc($res)) {
$va = $row['workingid'];
echo "<option value='$va'>$va</option>";
}
echo '</select>'; ?><input type="hidden" name="workingid" /></td>
</tr>
<tr>
<td class="style8">Department</td>
<td >
<? $res = $va;
$res = mysql_query("SELECT DepartmentID FROM tbldepartment")
or die("Invalid query: " . mysql_query());
//echo '<label>Select value:</label>';
echo '<select id="val" name="val" class=style8>';
echo '<option value="">-- Select One --</option>';
while ($row = mysql_fetch_assoc($res)) {
$va = $row['DepartmentID'];
echo "<option value='$va'>$va</option>";
}
echo '</select>'; ?><input type="hidden" name="DepartmentID" /></td>
</tr>
<tr>
<td class="style8">Designation</td>
<td>
<?
$res = $va;
$res = mysql_query("SELECT DesignationID FROM tbldesignation")
or die("Invalid query: " . mysql_query());
// echo '<label>Select value:</label>';
echo '<select id="desigID" name="desigID" class=style8>';
echo '<option value="">-- Select One --</option>';
while ($row = mysql_fetch_assoc($res)) {
$va = $row['DesignationID'];
echo "<option value='$va'>$va</option>";
}
echo '</select>'; ?><input type="hidden" name="DesignationID" /></td>
</tr>
<tr>
<td align="center" valign="bottom" colspan="2"><br>
<input name="insert" type="submit" id="insert" value="SUBMIT"><input type="reset" value="RESET"> </tr>
</table>
</form>
<?php
} else {
$EmployeeID = $POST['EmployeeID'];
$EmployeeName = $POST['EmployeeName'];
$workingid = $POST['workingid'];
$DepartmentID = $POST['DepartmentID'];
$DesignationID = $_POST['DesignationID'];
mysql_query("insert into tblemployee values('$EmployeeID', '$EmployeeName', '$rworkingid','$DepartmentID','$DesignationID') ") ;
echo "<p align=\"left\"><br><font color=\"blue\">The Profile has been inserted inside database.</font></p>";
echo"<br><h5><p align=\"left\">
<a href=\"http://localhost/forms/insert_data.php\" style=text-decoration:none>>>Insert again</a>|
<a href=\"http://localhost/forms/insert_main.php\" style=text-decoration:none>>>Back</a>
</p></h5><br>";
echo"<b><u>1.Particular</u></b><br>";
echo "<table border=\"0\" align=\"left\" cellpadding=\"2\" cellspacing=\"1.5\">";
echo "<tr>";
echo "<font face=\"Georgia\" size=\"10\">";
echo "<td>Employee ID<td>:</td></td>\n";
echo "<td><b>$EmployeeID</b></td>\n";
echo "</tr>";
echo "<tr>";
echo "<td>Employee name<td>:</td></td>\n";
echo "<td><b>$EmployeeName</b></td>\n";
echo "</tr>";
echo "<tr>";
echo "<tr>";
echo "<td>Working ID<td>:</td></td>\n";
echo "<td><b>$workingid</b></td>\n";
echo "</tr>";
echo "<td>Dept<td>:</td></td>\n";
echo "<td><b>$DepartmentID</b></td>\n";
echo "</tr>";
echo "<tr>";
echo "<td>Designation<td>:</td></td>\n";
echo "<td><b>$DesignationID</b></td>\n";
echo "</tr>";
echo "<tr>";
echo " </font></table>";
echo " <br>";
}?>