modify('+1 year'); } else { $date->modify('+1 month'); } $expiryDate = $date->format('Y-m-d'); // Update user record in the database try { $pdo = db(); $stmt = $pdo->prepare("UPDATE users SET subscription_plan = ?, subscription_expires_at = ? WHERE id = ?"); $stmt->execute([$plan, $expiryDate, $userId]); // Set a session flash message $_SESSION['flash_message'] = t('subscription_success_message'); // Redirect to profile page header('Location: profile.php'); exit; } catch (PDOException $e) { // In a real app, you would log this error die("Database error: " . $e->getMessage()); }