prepare("SELECT user_id FROM cvs WHERE id = ?"); $stmt->execute([$cv_id]); $cv = $stmt->fetch(PDO::FETCH_ASSOC); if (!$cv || $cv['user_id'] != $user_id) { // CV not found or does not belong to the user header('Location: dashboard.php?error=CV not found or permission denied.'); exit(); } // Delete the CV $stmt = $pdo->prepare("DELETE FROM cvs WHERE id = ? AND user_id = ?"); $stmt->execute([$cv_id, $user_id]); header('Location: dashboard.php?success=CV deleted successfully.'); exit(); } catch (PDOException $e) { // Log error and redirect error_log("CV Deletion Error: " . $e->getMessage()); header('Location: dashboard.php?error=An error occurred while deleting the CV.'); exit(); } ?>