prepare("SELECT * FROM clients WHERE client_id = ? AND user_id = ?"); $stmt->execute([$clientId, $_SESSION['user_id']]); $client = $stmt->fetch(PDO::FETCH_ASSOC); if (!$client) { // If client not found or doesn't belong to the user, redirect. header('Location: dashboard.php'); exit; } } catch (PDOException $e) { $errors[] = "Error fetching client data: " . $e->getMessage(); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $name = trim($_POST['name'] ?? ''); $status = trim($_POST['status'] ?? ''); if (empty($name)) { $errors[] = 'Client name is required.'; } if (!in_array($status, ['active', 'inactive'])) { $errors[] = 'Invalid status value.'; } if (empty($errors)) { try { $stmt = $pdo->prepare("UPDATE clients SET name = ?, status = ? WHERE client_id = ? AND user_id = ?"); $stmt->execute([$name, $status, $clientId, $_SESSION['user_id']]); log_audit_event('client_edit', $_SESSION['user_id'], "Client '{$name}' (ID: {$clientId}) updated."); header('Location: dashboard.php?client_id=' . $clientId . '&status=client_updated'); exit; } catch (PDOException $e) { $errors[] = "Error updating client: " . $e->getMessage(); } } } ?> Edit Client - ClientManager

Edit Client

Cancel

Client not found or you do not have permission to view it.

Back to Dashboard