Please I need assistance on how to get the input values of field that was generated by a loop:
if($moreDetails){
while($row=mysqli_fetch_assoc($moreDetails)){
$id="$row[id]";
$sname="$row[sname]";
$fname="$row[fname]";
$sub="$row[$subject]";
echo "
<tr>
<td>$id</td>
<td>$sname</td>
<td>$fname</td>
<td><label for='score'></label>
<input type='text' class='form-control' name='score'/>
<input type='hidden' name='assessment'/>
</td>
</tr>
";
}
}
My challenge is to get the input of the score entries.
You should give the inputs array-style names.
if($moreDetails){
while($row=mysqli_fetch_assoc($moreDetails)){
$id="$row[id]";
$sname="$row[sname]";
$fname="$row[fname]";
$sub="$row[$subject]";
echo "
<tr>
<td>$id</td>
<td>$sname</td>
<td>$fname</td>
<td><label for='score'></label>
<input type='text' class='form-control' name='score[$id]'/>
<input type='hidden' name='assessment[$id]'/>
</td>
</tr>
";
}
}
Then when you're processing the form, the $_POST
parameters will be arrays, so you can access $_POST['score'][$id]
and $_POST['assessment'][$id]
.
It's also strange that you don't have value="something"
in the hidden input. Are you using Javascript on the client side to fill this field in automatically?