Hi,
Can anybody help with this code? I get and undefined variable error when running the second script after passing variables over to it from the first script.
I am attempting to count the number of rows using mysql_numrows($sql_query) function.
Can anyone explain why on the second scripts I get the error undefined variable for num_rows.
Thanks,
Mike
Script 1.
<?
include ("../connection.php");
$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);
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\">Level</td>
<td align=\"center\">Ability</td>
<td align=\"center\">System</td>
</tr>";
while( $row = mysql_fetch_array( $sql_result ) )
{
$description3 = $row["description3"];
echo "
<tr>
<td>$description3</td>
<td align=center>
<select name=\"skl_lev3\">
<option name=\"1\">Guru</option>
<option name=\"2\">Expert</option>
<option name=\"3\">Intermediate</option>
<option name=\"4\">User</option>
<option name=\"5\">Novice</option>
<option name=\"0\">No Skill</option>
</select>
</td>
<td align=center>
<select name=\"ab_id\">
<option name=\"1\">1</option>
<option name=\"2\">2</option>
<option name=\"3\">3</option>
<option name=\"4\">4</option>
<option name=\"5\">5</option>
<option name=\"0\">0</option>
</select>
</td>
<td align=center>
<select name=\"system\">
<option name=\"character\">Character</option>
<option name=\"java\">Java</option>
<option name=\"both\">Both</option>
</select>
</td>
</tr>";
}
echo "</table>";
echo "<input type=\"hidden\" value=\"$num_rows\">";
echo "<p align=\"center\"><input type=\"submit\" name=\"$num_rows\">";
?>
Script 2
<?
$inserts = $num_rows;
for ($i=0;$i<$inserts;$i++)
{
include ("../connection.php");
$sql = "INSERT INTO emp_skills (result_id, skl_lev3, ab_id, system)
VALUES ('$result_id', '$skl_lev3', $ab_id, '$system')";
$sql_result = mysql_query($sql,$connection) or die ("Query Execute");
}
echo "<table cellpadding=0 cellspacing=0 border=1 width=760 align=center>";
echo "
<tr><br>
<td align=\"center\">Level: $skl_lev3</td>
</tr>
<tr>
<td align=\"center\">Ability ID: $ab_id</td>
</tr>
<tr>
<td align=\"center\">System: $system</td>
</tr>
<tr>
<td align=\"center\">Name: $result_id</td>
</tr>
</table>";
?>