35 lines
1.0 KiB
PHP
35 lines
1.0 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
|
|
if (isset($_GET['user_service_id'])) {
|
|
$user_service_id = $_GET['user_service_id'];
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
try {
|
|
$pdo = db();
|
|
// Verify the user owns this subscription before cancelling
|
|
$stmt = $pdo->prepare("UPDATE user_services SET status = 'cancelled' WHERE id = ? AND user_id = ?");
|
|
$stmt->execute([$user_service_id, $user_id]);
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
$_SESSION['message'] = 'Subscription cancelled successfully.';
|
|
} else {
|
|
$_SESSION['error'] = 'Could not cancel subscription. It might have been already cancelled or you do not have permission to perform this action.';
|
|
}
|
|
} catch (PDOException $e) {
|
|
$_SESSION['error'] = 'Database error: ' . $e->getMessage();
|
|
}
|
|
} else {
|
|
$_SESSION['error'] = 'Invalid request.';
|
|
}
|
|
|
|
header('Location: dashboard.php');
|
|
exit;
|