Need to change date is triggered, but date is not being changed

I am making a registration system and having problems detecting an issue with my code. In this part, the admin is adding a new event. This worked like a charm until I added some checks to it:

There are two dates involved: the date of the event ( event_date ) and the date that the registrations close ( end_date ) . If the end_date is not entered, the event_date is taken as the default for the closing of the registrations (no problem here).

What I am trying to add to this is a test whether the closing date (end_date) is mistakenly entered as a date before today, or a date after the event date. If it is, it should be changed to the event_date, and redirect to the same page with a message displayed that explains what happened.

The error is being detected okay (and the error message displayed) but the end_date is not being changed if it is before today’s date, only if it is after the event_date. And inside the if clause, I cannot get anything to echo out for me to test this.

Is there any error in this code that I missed, that jumps out at anyone? I have tested things until I’m blue in the face and not able to find it. But I don’t want to just forget about this check.

 // If closing date exists, format it. If not, set it to the event date.
            if ($end_month != '' && $end_day != '' && $end_year != '') {
                $data['end_date'] =  $end_year . '-' . $end_month . '-' . $end_day;
            } else {
                $data['end_date'] = $data['event_date'];
            // If closing date is before today's date or after event date, set it to event date
            if ($data['end_date'] < date('Y-m-d') || $data['end_date'] > $data['event_date']) {
                $data['end_date'] = $data['event_date'];
                $msg = 'wrong date';
            }  else {
                $msg = '';
            // Add new event to database
            $event_id = $event->addEvent($data);
            // If closing date is before today's date or after event date, redirect with message about the change to the closing date
            if ($msg = 'wrong date') {
                redirect('event_form.php', 'You entered an invalid date (prior to today\'s date or after the event date), so we changed it to the event date. Other than that, the event was added successfully', 'error');

Dates are more than likely being converted to math, e.g. 2015 - 03 - 27
Wrap each date in strtotime() when comparing.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.