I'm working on a script for myself to keep up with student grades online. For example, I have a form where each student name is displayed and then a box for me to input their test grade. I need to be able to insert each student ($userid) and their grade ($grade) in a database table. My problem is getting the script to read each student array from the form once submitted.
Here's a simplified version of the form:
<tr>
<td>Jane Doe</td><input name="name[userid]" type="hidden" value="<?php echo $thisstudent['userid']; ?>">
<td><input type="text" name="name[grade]" size="3" maxlength="3"></td>
</tr>
<td>John Doe</td><input name="name[userid]" type="hidden" value="<?php echo $thisstudent['userid']; ?>">
<td><input type="text" name="name[grade]" size="3" maxlength="3"></td>
</tr>
...and so on....
Basically in my form, each table row will list the name of the student and a place for the grade. Within each row, I have also placed a hidden input to keep track of the student's userid.
Question - Did I name the form fields correct?
Now for the processing script, I know I will need a foreach statement but I'm not sure how to construct it based on what information is coming from the form. Maybe something like:
foreach ($HTTP_POST_VARS as $value)
{
$query="INSERT INTO grades VALUES ('$value['userid']', '$value['grade']')";
$result=mysql_query($query);
}
But this doesn't work!
Thanks for ANY help!