I have a page displaying around 103 records. Each record is a student record that contains a unique ID called SOMS_KEY. I am adding a grade for each student.
The form where I can enter in all grades:
$studentYearlist = $db->sql_query("SELECT * FROM atlas_tl_students WHERE Class_Year = $Course_Year");
while ($row = $db->sql_fetchrow($studentYearlist)) {
$SOMS_KEY = $row['SOMS_KEY'];
$Name_First = $row['Name_First'];
$Name_Last = $row['Name_Last'];
if (!$studentYearlist) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
//<!-- BEGIN Student Row -->"
echo "<tr><td align=\"center\">$SOMS_KEY</td>"
. " <td align=\"left\">$Name_First $Name_Last</td>"
. " <td><input type='text' name='add_irat_gr[]' size='3' maxlength='3'></td>"
. "</tr>";
}
//-- END Student Row -->"
The very last record I pull with this query is SOMS_KEY = 407
I action for this form sends to to a page to insert all these values. The problem is the value 407 is being entered for all 100 records I have. However each student has their own unique SOMS_KEY.
Here is the code I have to INSERT:
$add_irat_gr_value= $_POST['add_irat_gr'];
$SOMS_KEY = $_POST['SOMS_KEY'];
$Session_ID = $_POST['Session_ID'];
$grade_type = 'IRAT';
//Go get the academic year value from config table
$GetYear = $db->sql_fetchrow($db->sql_query("SELECT Academic_Year from ".$prefix."_tl_config"));
if (!$GetYear) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}
$Academic_Year = $GetYear['Academic_Year'];
/* Do the for each statement */
foreach ($add_irat_gr_value as $add_irat_gr) {
$sql = "INSERT INTO ".$prefix."_tl_session_grades (SOMS_KEY, Session_ID, grade, grade_type, Academic_Year)". "VALUES ('$SOMS_KEY','$Session_ID','$add_irat_gr','$grade_type', '$Academic_Year')";
if (!$sql) {echo("<p>Error performing query: " . mysql_error() . "</p>");}
$result = $db->sql_query($sql);
}
Where have I gone wrong? I just can't see it.
I have the text box as an array. Is this correct?
type='text' name='add_irat_gr[]'
This value needs to pair up with each individual SOMS_KEY for each student.