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.