The form being used to populate the database has to be kept up to date with the respective fields within the database.
Therefore a dynamic form field is required:
<table>
<tr>
<th>Intermediate</th>
<th>Advanced</th>
<th>No selection</th>
</tr>
<?php
$sth = $dbh->prepare("SELECT SkillName FROM Skill");
$sth->execute();
$tempCounter = 1;
while($row = $sth->fetch()) {
echo ("<tr>
<td colspan=\"3\">
<label for=\"td".$tempCounter."\">".$tempCounter.". ".$row['SkillName']."</label>
</td>
</tr>");
echo ("
<tr>
<td>
<input type=\"radio\" name=\"".$row['SkillName']."\" id=\"tdA".$tempCounter."\" value=\"1\"/>
</td>
<td><input type=\"radio\" name=\"".$row['SkillName']."\" id=\"tdB".$tempCounter."\" value=\"2\"/>
</td>
<td><input type=\"radio\" name=\"".$row['SkillName']."\" id=\"tdC".$tempCounter."\" value=\"\" /></td>
</tr>");
$tempCounter++;
}
?>
</table>
However, I don't know how to go about inserting data into the database when it is not clear what the data may be (specifically the SkillName)
In pseudocode it would be ("INSERT INTO PersonSkill (PersonID, SkillName, SkillValue) values ($personid, $skillname, $skillvalue)")
where $personid is already defined, $skillname is unknown at the time of writing the form, and $skillvalue is an integer.
So if the HTTP header information might look something like
- [personid] => 101
- [firstaid] => 2
- [swimming] => 1
- [mechanics] => 0
- [firearms] =>
- [athletics] => 2
How might I iterate over such values? I could always use the database itself to anticipate the values, but the final piece of the puzzle is eluding me...
while($row = $sth->fetch()) {
if (isset($_POST[''.$row['SkillName'].'']))
// And er... save some variable at this point I suppose, or perhaps append to an array...
}