= strtotime($end_datetime)) { header('Location: dashboard.php?status=error&message=End+time+must+be+after+start+time'); exit; } try { $stmt = db()->prepare("INSERT INTO coach_availability (coach_id, start_time, end_time) VALUES (?, ?, ?)"); $stmt->execute([$coach_id, $start_datetime, $end_datetime]); header('Location: dashboard.php?status=success&message=Availability+added+successfully'); exit; } catch (PDOException $e) { // Log error and redirect error_log('Error adding availability: ' . $e->getMessage()); header('Location: dashboard.php?status=error&message=Could+not+add+availability'); exit; } } // Redirect if accessed directly without POST header('Location: dashboard.php'); exit;