submit data in a textbox from a while loop to database

I need to enter scores for all subjects offered by all students in a class simultaneously. So I retrieved the students ID, retreived the list of subjects being offered by the students and placed a textbox under each subject. Now, I want to submit the score in the database as well as the subject name and the student ID, but the score is not storing, just the subject name and the student ID.
Here is my code

<form method="post">
<?php
include "includes/dbcon.php";
$subject_name ="";
echo "<table border='1'><thead><tr><td>Students Name</td>";
$query_subjects = mysqli_query($link,"SELECT * FROM junior_subjects ORDER BY subject_name ASC");
while ($row_subject=mysqli_fetch_array($query_subjects))
{
    $subject_name .= $row_subject['subject_name'];
    echo "<td>".$row_subject['subject_name']."</td>";
}
echo "</tr></thead>";
$query_students = mysqli_query($link,"SELECT * FROM students WHERE class_cat='Junior'");
while ($row_students=mysqli_fetch_array($query_students))
{
    $student_id = $row_students['student_id'];
    echo "<tr><td>".$row_students['student_id']."</td>";
    $query_subjects2 = mysqli_query($link,"SELECT * FROM junior_subjects ORDER BY subject_name ASC");
    while ($row_subject2 =mysqli_fetch_array($query_subjects2))
    {
    $subject_name2 =$row_subject2['subject_name'];
    echo "<td><input type='text' hidden name='$subject_name2'>
    <input type='text' size='4' name='$subject_name2'></td>";
    /////
if (isset($_POST['submit']))
{
    $score = $_POST[$subject_name2];
    mysqli_query($link,"INSERT INTO score_sheet(student_id,subject_name,score) VALUES('$student_id','$subject_name2','$score') ");
}
}
}

?>
<input type='submit' name='submit'>
</form>


Source: mysql

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.