dongshadu4498 2016-08-19 22:10
浏览 21

设置为12月时,PHP重复发生的事件脚本崩溃

I have an event entry form that allows you to set an event to recur on a monthly basis on a specified date. Everything works just fine until you set it to stop in December. When you save it, it looks like to loads for a while but then eventually crashes.

Setting it to stop any other month works perfectly fine an updates instantly. It returns a 500 error so I don't think it's a timeout problem (This site returns a timeout notice when that's the case.).

Here's the code

if ($_REQUEST["Daily"] == 'numbered') {
    $endMonth = $_REQUEST['month'];
    $exd = $_REQUEST['everyXdays'];
    $inter = '-1';
    if (($_REQUEST['everyXdays'] != '-1') && ($_REQUEST['everyXdays'] != $date1->format('d'))) {
        $date1->setDate($date1->format('Y'),(int) $_REQUEST['month'],(int) $_REQUEST['everyXdays']);
    }
    for($date; $date->format('m') <= $endMonth; $date->add(new DateInterval('P1M'))) {
        $eventDays[] = $_REQUEST['everyXdays'] < '0'
            ? $date->format('Y-m-t')
            : $date->format('Y-m-').str_pad($_REQUEST['everyXdays'],2,"0",STR_PAD_LEFT);
    }
}

The code creates an array of events that get inserted into the database as child events. The original parent is then set to the final instance of the event. Basically the parent is moved to the end of the date range and creates child instances behind it.

The second IF statement says if 'everyXdays' is not the same as the parent's original start date, set the day as 'everyXdays'.

The FOR loop is what creates the event array. $date is the original start date that increments on each loop and $date1 is the final event instance's date.

A function then inserts them all into a database. I'm not including the function because, like I said earlier, it works perfectly fine when it's set to any other month. So I'm sure that's not the problem.

  • 写回答

2条回答 默认 最新

  • duanmiaosi0150 2016-08-19 22:14
    关注

    I'm not sure, as I cannot run php code now, but I think, if you choose December, $endMonth gets the value 11, but $date->format('m') is 12, so the loop does not run a single time.
    Can you please check for this bug?

    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路