I have this code that is causing me huge problems at the moment. The code is below concerning two pages. The first page returns a vraiable amount of rows in which users then have the option of entering numeric values. These textbox values along with the original rows returned are passed to the second page for insertion in my database.
The problem is that it only enters inserts the last row from the first page. I cannot figure out how to get it to work for all rows. Can anybody help???!
Page 1<?
$sql = "SELECT skill_hier_lev3.skl_lev3, skill_hier_lev3.description3 FROM skill_hier_lev3, skill_hier_lev2
WHERE skill_hier_lev3.skl_lev2 = skill_hier_lev2.skl_lev2
AND skill_hier_lev3.skl_lev2 = '$skl_lev2'";
$sql_result = mysql_query($sql,$connection) or die ("Query Execute");
$num_rows = mysql_numrows($sql_result);
$sql4 = "SELECT * FROM employee";
$sql_result4 = mysql_query($sql4,$connection) or die ("Query Execute");
echo "
<table width=300 border=0 align=center>
<tr align=left>
<td valign=top align=center>
<b>Please select the employee that you wish to enter skills for:</b><p>
";
echo "<select name=\"result_id\">";
while ($row = mysql_fetch_array($sql_result4))
{
$name = $row["name"];
$result_id = $row["result_id"];
echo "<option value=\"$result_id\">$name</option>";
}
echo "</select>";
echo "
</td>
</tr>
</table>
";
echo "Number of available skills in the section is <b>$num_rows</b>";
echo "<table cellpadding=0 cellspacing=0 border=1 width=600 align=center>";
echo "
<tr><br>
<td align=\"center\">Description</td>
<td align=\"center\">Character Ability</td>
<td align=\"center\">Java Ability</td>
</tr>";
while ($row = mysql_fetch_array($sql_result))
{
$description3 = $row["description3"];
$skl_lev3 = $row["skl_lev3"];
echo"
<tr>
<td align=left>$description3</td>
<td align=center><input type=number size=1 name=jab_id class=textbox1></td>
<td align=center><input type=number size=1 name=cab_id class=textbox2></td>
</tr>
";
}
echo "</table>";
echo "<input type=\"hidden\" name=\"description3\" value=\"$description3\">";
echo "<input type=\"hidden\" name=\"skl_lev3\" value=\"$skl_lev3\">";
echo "<input type=\"hidden\" name=\"num_rows\" value=\"$num_rows\">";
echo "<p align=\"center\"><input type=\"submit\" name=\"button\">";
?>
Page 2.
<?
$sql = "select skl_lev3, description3
from skill_hier_lev3, skill_hier_lev2
where skill_hier_lev3.skl_lev2 = skill_hier_lev2.skl_lev2
and skill_hier_lev3.skl_lev3 = '$skl_lev3';";
$sql_result = mysql_query($sql,$connection) or die ("Query Execute1");
$sql2 = "select result_id, name from employee where result_id='$result_id';";
$sql_result2 = mysql_query($sql2,$connection) or die ("Query Execute2");
$num_rows = mysql_numrows($sql_result);
echo "<table cellpadding=0 cellspacing=0 border=1 width=760 align=center>";
echo "
<tr><br>
<td align=\"center\" width=200>Description</td>
<td align=\"center\">Character Ability</td>
<td align=\"center\">Java Ability</td>
</tr>";
while ( $row = mysql_fetch_array( $sql_result ) )
{
$description3 = $row["description3"];
$skl_lev3 = $row["skl_lev3"];
echo "
<tr>
<td>$description3</td>
<td>$skl_lev3</td>
<td>$jab_id</td>
<td>$cab_id</td>";
$sql5 = "INSERT INTO emp_skills (result_id, skl_lev3, java_ab_id, char_ab_id)
VALUES ('$result_id', '$skl_lev3', $jab_id, $cab_id);";
$sql_result5 = mysql_query($sql5,$connection) or die ("Query Execute5");
echo"
</td>";
}
echo "</table>";
?>