0
<form name="reg" id="reg" method="post" action="<?php echo $editFormAction; ?>">
              <table width="100%" border="0" align="center" cellpadding="4" cellspacing="4" style="text-align:left;">
                <tbody>
                  <tr>
                    <th width="117" height="39" bgcolor="#FFE1CC">Student RollNo</th>
                    <th bgcolor="#FFE1CC">Student Name</th>
                    <th width="100" bgcolor="#ECFAFF">Old Status</th>
                    <th width="1" bgcolor="#FFE1CC">Present</th>
                    <th width="1" bgcolor="#FFE1CC">Absent</th>
                    <th width="1" bgcolor="#FFE1CC">Leave</th>
                    <th width="1" bgcolor="#FFE1CC">Holiday</th>
                  </tr>
                  <?php
                             while ($students = mysql_fetch_array($result)) {
                          ?>
                  <tr>
                    <td bgcolor="#EAFAFF" class="table1"><?php $id = $students['memberid']; ?><?php echo $_POST['department']; ?>-<?php echo $students['rollno']; ?></td>
                    <td bgcolor="#EAFAFF" class="table1"><?php echo $students['fullname']; ?></td>
                    <td align="center" bgcolor="#ECFAFF" class="table1"><?php echo $students['current']; ?></td>
                    <td width="1" align="center" bgcolor="#FFE2D5" id="present"><input type="radio" name="present[<?php echo $students['memberid']; ?>]" value="Present" /></td>
                    <td width="1" align="center" bgcolor="#FFE2D5" id="absent"><input type="radio" name="present[<?php echo $students['memberid']; ?>]" value="Absent" /></td>
                    <td width="1" align="center" bgcolor="#FFE2D5" id="leave"><input type="radio" name="present[<?php echo $students['memberid']; ?>]" value="Leave" /></td>
                    <td width="1" align="center" bgcolor="#FFE2D5" id="holiday"><input type="radio" name="present[<?php echo $students['memberid']; ?>]" value="Holiday" /></td>
                  </tr>
                  <input name="fullname" type="hidden" value="<?php echo $students['fullname']; ?>">
                  <input name="rollno" type="hidden" value="<?php echo $students['rollno']; ?>">
                  <input name="percent" type="hidden" value="<?php echo $students['percent']; ?>">
                  <input name="department" type="hidden" value="<?php echo $_REQUEST['department']; ?>">
                  <input name="semester" type="hidden" value="<?php echo $_REQUEST['semester']; ?>">
                  <input name="session" type="hidden" value="<?php echo $_REQUEST['sessionfrom']; ?>-<?php echo $_REQUEST['sessionto']; ?>">
                  <input name="subject" type="hidden" value="<?php echo $_REQUEST['subject']; ?>">
                  <input name="date" type="hidden" value="<?php echo date("m-d-Y"); ?>">
                  <?php
                    }
                  ?>
                  <tr>
                    <td colspan="6" style="vertical-align:middle; text-align: center;"><br />
                      <input id="Submit" type="submit" name="Submit" value="Submit" style="text-align: center; background-color: #000000; color: #ffffff; border: 1px #000000 solid;" /></td>
                    <td>&nbsp;</td>
                  </tr>
                </tbody>
              </table>
              <input type="hidden" name="MM_insert" value="reg" />
            </form>
            <?php
                    if (($_POST["MM_insert"] == "reg")){
                       foreach($_POST['present'] as $student_id => $value) {

                          $sql = "UPDATE members SET current = '".$value."' WHERE memberid = '".$student_id."' ";
                          $result = mysql_query($sql);

                          $sql1 = "INSERT INTO student_attendance (department, semester, session, subject, current, percent, date) VALUES ('".$_REQUEST['department']."','".$_REQUEST['semester']."','".$_REQUEST['session']."','".$_REQUEST['subject']."','$value','".$_REQUEST['percent']."','".$_REQUEST['date']."')";
                          $result = mysql_query($sql1);
                       }
                       header("Location: attendance.php");
                    }


?>

你好上面是我的代码,一切似乎都工作正常。有姓名的学生列表,rollno 也出现在成员表中,提交时,出席学生的状态到缺席或出席工作正常,它进入到出席记录个人,示例提交 20 名学生的记录,20 行添加不同的当前状态,但是学生姓名和 rollno 将变为 Null.... 我目前删除了 rollno 和 studentname,因为只有第一个学生姓名重复了 20 次,而且 rollno 也是如此。

 <?php
                if (($_POST["MM_insert"] == "reg")){
                   foreach($_POST['present'] as $student_id => $value) {

                      $sql = "UPDATE members SET current = '".$value."' WHERE memberid = '".$student_id."' ";
                      $result = mysql_query($sql);

                      $sql1 = "INSERT INTO student_attendance (department, semester, session, subject, current, percent, date) VALUES ('".$_REQUEST['department']."','".$_REQUEST['semester']."','".$_REQUEST['session']."','".$_REQUEST['subject']."','$value','".$_REQUEST['percent']."','".$_REQUEST['date']."')";
                      $result = mysql_query($sql1);
                   }
                   header("Location: attendance.php");
                }


?>

请帮我纠正它,我不能使用具有更多值的 foreach 函数你能告诉如何使用 while 或 for 下面的代码,所以所有学生姓名,包括状态在内的卷都提交到出席视图表?

4

1 回答 1

0

每当您需要为特定表单字段提供多个值时,您需要将表单字段名称的日期类型设置为数组因此您需要在输入隐藏字段中将名称设置为fullname[]而不是fullname 这将存储您的所有表单中的值,它不会被覆盖。

如果你想存储那个特定学生的全名,那么你可以像这样设置你的隐藏字段 -

<input name="fullname[<?php echo $students['memberid']; ?>]" type="hidden" value="<?php echo $students['fullname']; ?>"> 

这也应该对其他隐藏字段进行。

于 2012-12-26T06:59:10.463 回答