Php Foreach循环错误地在一列中过帐值

Php Foreach循环错误地在一列中过帐值,php,mysql,Php,Mysql,请帮帮我。我开发了一个考勤记录,通过表格获取数据。用户完成后,所有值都将发布到mysql。这是表格: <form action="processAttRegister.php" method="post" name="frmAttregister"> <table width="96%" border="1" align ="center" cellpadding="0" cellspacing="0" id="projectOverview"> <tr&g

请帮帮我。我开发了一个考勤记录,通过表格获取数据。用户完成后,所有值都将发布到mysql。这是表格:

<form action="processAttRegister.php" method="post" name="frmAttregister">
<table width="96%" border="1" align ="center" cellpadding="0" cellspacing="0" id="projectOverview">
    <tr>
        <th width="72">Date</th>
        <th width="156">Name</th>
        <th width="50">Present</th>
        <th width="152">Reason For Absence</th>
        <th width="44">Time In</th>
        <th width="46">Time Out</th>
        <th width="107">Remarks</th>
        <?php    
            // we'll increase this new variable by 1 on each loop,
            // to make sure it's always unique
            $count = 0; 

            $atts = mysql_query("SELECT * FROM tblemployeedata WHERE grade>4 AND section=3");
            while($att = mysql_fetch_array($atts)) {

            // increase the count variable by 1
            $count++;

            // $count is added inside each ID attribute below to ensure uniqueness.
        ?>
        <tr id="empattlist">
            <td><input name="date[]" id="date<?php echo $count; ?>" type="text" value="<?php echo date("Y-m-d");?>" size="12"/></td>
            <td><input name="name[]" id="name<?php echo $count; ?>" type="text" value="<?php echo $att["empID"];?>" readonly hidden /><?php echo $att["firstname"]." ".$att["surname"]."(".$att["empID"].")";?></td>
            <td>
                <div align="center">
                    <input name="emppresent[]" id="emppresent<?php echo $count; ?>" type="checkbox" value="Yes" onclick="hideShowElements(<?php echo $count; ?>)"/>
                    <input type="hidden" name="emppresent[]" id="emppresent<?php echo $count; ?>" value="No"/>
                </div>
            </td>
            <td id="abs_reason">
                <select name="absentReason[]" id="absentReason<?php echo $count; ?>">
                    <option value="" selected="selected">-</option>
                    <option value="Other">Other</option>
                    <option value="Funeral">Attending Funeral</option>
                    <option value="Sick">Sick</option>
                </select>

            </td>
            <td><input type="text" name="timein[]" id="timein<?php echo $count; ?>" size="7" /></td>
            <td><input type="text" name="timeout[]" id="timeout<?php echo $count; ?>" size="7"/></td>
            <td>
            <textarea name="remarks[]" cols="15" rows="1" id="remarks<?php echo $count; ?>" ></textarea>
            </td>
        </tr>
        <?php
            // pass count to the function, also on the other function call below.
            echo '<script type="text/javascript">initiallyHideElements(' . $count . ');</script>';
            }

        ?>
        <tr>
            <td colspan="7">
            <div align="center">
            <input name="postAttendance" type="submit" id="postAttendance" value="Submit" align="center" />

            </div>
            </td>
        </tr>
</table>

过帐操作正常,但“present”中的值过帐错误。只有前三条记录被正确发布。

$\u POST['emppresent']将为您提供一个数组!!如果修复缩进,您可能会很快看到错误。我为循环提交了错误的代码。这是正确的oneforeach($_POST[“date”]作为$k=>$v){if(!empty($v)){$attendaceData=“插入到tblattendanceregister(日期、员工、当前、缺席原因、时间、超时、备注)值(“.”.mysql\u real\u escape\u string($v)。“,”.mysql\u real\u escape\u string($_POST[$k]),“,”.mysql\u real\u escape\u string\u string($POST[$k])[$k])。“,”.mysql_real_escape_string($_POST['absentReason'][$k])。“,”.mysql_real_escape_string($_POST['timein'][$k])。“,”.mysql_real_escape_string($_POST['timeout'][$k])。”,“.mysql_real__escape_string($_POST['备注'[$k])。”)”);$POST=mysql_查询($attendedta)}您好,我已经解决了!!!!我删除了复选框,并将其替换为下拉列表框。
    foreach($_POST["date"] as $k) 
    {
        if(!empty($v)) 
            {
              $attendaceData = "INSERT INTO  tblattendanceregister (date, employee,present,absentReason,timeIn,timeOut,remarks) 
                            VALUE ('".$k."', '".$_POST['name']."', '".$_POST['emppresent']."', '".$_POST['absentReason']."',
                                    '".$_POST['timein']."', '".$_POST['timeout']."', '".$_POST['remarks']."')";
              $post=mysql_query($attendaceData);
            }
    }

    if($post){
        header("Location: AttendanceRegister.php");
    }
    else
    {
        $error=mysql_error();
        header("Location: AttendanceRegister.php?post=error&problem=$error");
    }
}