Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 取消选中mysql列表底部的复选框值_Php_Mysql_Arrays_Checkbox - Fatal编程技术网

Php 取消选中mysql列表底部的复选框值

Php 取消选中mysql列表底部的复选框值,php,mysql,arrays,checkbox,Php,Mysql,Arrays,Checkbox,我有一张有支票盒的桌子。我使用数组来处理这个问题。但不知何故,在提交之后。在mysql中,取消选中的值始终位于列表的底部。这是我的密码: $mystudentID = $_POST['studID']; $mystudATT = $_POST['myattt']; $number = count($mystudentID ); for ($i=0; $i<$number; $i++) { $studID = $mystudentID[$i]; $studAtt

我有一张有支票盒的桌子。我使用数组来处理这个问题。但不知何故,在提交之后。在mysql中,取消选中的值始终位于列表的底部。这是我的密码:

$mystudentID = $_POST['studID']; 
$mystudATT = $_POST['myattt']; 
$number = count($mystudentID ); 

for ($i=0; $i<$number; $i++) 
{
    $studID = $mystudentID[$i]; 
    $studAtt = $mystudATT[$i]; 

    $sql="
        INSERT INTO mate_student_att
        (attendance,date,studID) 
        VALUES 
        ('$studAtt','$_POST[myDate]','$studID')
    ";

    if (!mysqli_query($con,$sql))
    {
        die('Error: ' . mysqli_error($con));
    }
    echo "1 record added";
} 
mysqli_close($con);
$mystudentID=$\u POST['studID'];
$mystudATT=$_POST['myattt'];
$number=count($mystudentID);
对于($i=0;$iDevZer0是正确的。
将所有复选框保存到db中的唯一方法是在html表单中创建一个隐藏字段,并显示所有复选框(无论其初始状态或最终状态如何)。
例如,您可以像这样保留所有复选框名称

 studID1,studID2,studID3,studID4 
在隐藏字段的值中。 此隐藏字段将被发布。 然后,必须拆分/分解隐藏字段的值,以获得带有复选框名称的数组。 循环到此数组中,如果在post参数中找到每个复选框名称的名称,则表示选中了他的复选框,并将其插入到考勤为1的数据库中,否则将其插入考勤为0的数据库中。 如果你做不到,我可以相应地修改你的代码

编辑

你的表格

<input type='hidden' name='allStudIDs' value='studID1,studID2,studID3,studID4,studID5,studID6,studID7' />
<input type='checkbox' name='studID1" />student 1
<input type='checkbox' name='studID2" />student 2
<input type='checkbox' name='studID3" />student 3
<input type='checkbox' name='studID4" />student 4
<input type='checkbox' name='studID5" />student 5
<input type='checkbox' name='studID6" />student 6
<input type='checkbox' name='studID7" />student 7

学生3
学生6

问题不清楚Sir我的意思是我的未选中框从未进入我的数组。我们如何将未选中值存储到mysql数据库未选中的复选框不会通过表单post传输,缺少给定的复选框决定它是否未选中。我刚刚了解到这一点。有什么地方可以解决这个问题吗?我以前的同事mment也有它的解决方法。改变表单发布行为是没有办法的,你必须通过确定复选框何时不存在来调整你的代码。
$allStudentIDs = $_POST['allStudIDs']; 
$mystudentID = $_POST['studID']; 
$tempArray = explode(",", $allStudentIDs);

for ($i=0; $i<count($tempArray); $i++) 
{
    $studID = $tempArray[$i];
    if (isset($_POST[$tempArray[$i]])) 
    {
        $studAtt = 1; 
    }
    else
    {
        $studAtt = 0; 
    }

    $sql="
        INSERT INTO mate_student_att
        (attendance,date,studID) 
        VALUES 
        ('$studAtt','$_POST[myDate]','$studID')
    ";

    if (!mysqli_query($con,$sql))
    {
        die('Error: ' . mysqli_error($con));
    }
    echo "1 record added";
} 
mysqli_close($con);