在mysql中使用多维数组存储$ _POST

时间:2023-01-21 21:28:21

I have a calendar for which each day has a checkbox like this:

我有一个日历,每天都有一个像这样的复选框:

    <input type="hidden" name="uevent['.$urange.']['.$list_day.']['.$month.']['.$year.']" value="0"><input type="checkbox" id="calendarcheck" name="uevent['.$urange.']['.$list_day.']['.$month.']['.$year.']" checked>$list_day

where $urange is one type of calendar out of three.

其中$ urange是三种日历中的一种。

When submit is clicked, I would like to store in mysql each day whether it was checked or not. So I generated this code:

点击提交后,我想每天都在mysql中存储是否被检查过。所以我生成了这段代码:

    print_r($_POST);

    $big_query='INSERT INTO `sdcheckings` (`email`,`urange`,`cyear`,`cmonth`,`cday`,`dchecked`,`tcheck`) VALUES ';

    for($i=0;$i<count($_POST[$row[0]]);$i++)
    {
        for($j=0;$j<count($_POST[$row[0]][$i]);$j++)
        {
            for($k=0;$k<count($_POST[$row[0]][$i][$j]);$k++)
            {
                if($k!=0)
                    $big_query.=', ';
                $dchecked = $_POST[$row[0]][$i][$j][$k];
                $big_query.='('.$_SESSION['email'].',  '.$row[0].',  '.$i.',  '.$j.',  '.$k.', '.$dchecked.', CURRENT_TIMESTAMP) ';
            }
        }
    }
     $adddates = mysql_query($big_query);

When I tested it by checking a couple of dates (february 4th, 2016 and februray 12th, 2016), I got the following:

当我通过检查几个日期(2016年2月4日和2016年12月12日)进行测试时,我得到以下信息:

Array ( [uevent] => Array ( [1] => Array ( [4] => Array ( [02] => Array ( [2016] => on ) [3] => Array ( [2016] => 0 ) ) [5] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [6] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [7] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [8] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [9] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [10] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [11] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [12] => Array ( [02] => Array ( [2016] => on ) [3] => Array ( [2016] => 0 ) ) [13] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [14] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [15] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [16] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [17] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [18] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [19] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [20] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [21] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [22] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [23] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [24] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [25] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [26] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [27] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [28] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [29] => Array ( [02] => Array ( [2016] => 0 ) [3] => Array ( [2016] => 0 ) ) [1] => Array ( [3] => Array ( [2016] => 0 ) ) [2] => Array ( [3] => Array ( [2016] => 0 ) ) [3] => Array ( [3] => Array ( [2016] => 0 ) ) [30] => Array ( [3] => Array ( [2016] => 0 ) ) [31] => Array ( [3] => Array ( [2016] => 0 ) ) ) ) [submit] => Update )

数组([uevent] =>数组([1] =>数组([4] =>数组([02] =>数组([2016] =>开启] [3] =>数组([2016] => 0 ))[5] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[6] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[7] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[8] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[9] = >数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[10] =>数组([02] =>数组([2016] = > 0)[3] =>数组([2016] => 0))[11] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] = > 0))[12] =>数组([02] =>数组([2016] =>开)[3] =>数组([2016] => 0))[13] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[14] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[15] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[16 ] =>数组([02] =>数组([2016 ] => 0)[3] =>数组([2016] => 0))[17] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016 ] => 0))[18] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[19] =>数组([] 02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[20] =>数组([02] =>数组([2016] => 0)[ 3] =>数组([2016] => 0))[21] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0)) [22] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[23] =>数组([02] =>数组( [2016] => 0)[3] =>数组([2016] => 0))[24] =>数组([02] =>数组([2016] => 0)[3] =>数组( [2016] => 0))[25] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[26] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0))[27] =>数组([02] =>数组([2016] => 0 )[3] =>数组([2016] => 0))[28] =>数组([02] =>数组([2016] => 0)[3] =>数组([2016] => 0 ))[29] =>数组([02] =>数组([201] 6] => 0)[3] =>数组([2016] => 0))[1] =>数组([3] =>数组([2016] => 0))[2] =>数组( [3] =>数组([2016] => 0))[3] =>数组([3] =>数组([2016] => 0))[30] =>数组([3] =>数组([2016] => 0))[31] =>数组([3] =>数组([2016] => 0))))[提交] =>更新)

The database did not store anything. I suspect that my loops are not correct. How can that be done?

数据库没有存储任何内容。我怀疑我的循环不正确。怎么办?

when printing out at the end $big_query, I get just this:

当在$ big_query结束时打印出来时,我得到了这个:

INSERT INTO `sdcheckings` (`email`,`urange`,`gender`,`cyear`,`cmonth`,`cday`,`dchecked`,`tcheck`) VALUES

1 个解决方案

#1


0  

        foreach($_POST['uevent'][$row[0]] as $yearnum => $postyear)
        {
            foreach($postyear as $monthnum => $postmonth)
            {
                foreach($postmonth as $daynum => $postday)
                {
                    if($firstcoma>0)
                        $big_query.=', ';
                    $firstcoma++;

                    if(strcmp($postday,"on")==0)
                        $postday=1;

                    $big_query.='("'.$_SESSION['email'].'",  '.$row[0].',  "'.$row[1].'",  '.$yearnum.',  '.$monthnum.',  '.$daynum.', '.$postday.', CURRENT_TIMESTAMP) ';
                }
            }
        }

#1


0  

        foreach($_POST['uevent'][$row[0]] as $yearnum => $postyear)
        {
            foreach($postyear as $monthnum => $postmonth)
            {
                foreach($postmonth as $daynum => $postday)
                {
                    if($firstcoma>0)
                        $big_query.=', ';
                    $firstcoma++;

                    if(strcmp($postday,"on")==0)
                        $postday=1;

                    $big_query.='("'.$_SESSION['email'].'",  '.$row[0].',  "'.$row[1].'",  '.$yearnum.',  '.$monthnum.',  '.$daynum.', '.$postday.', CURRENT_TIMESTAMP) ';
                }
            }
        }