Heray-Was-Here
Server : LiteSpeed
System : Linux uk-fast-web1372.main-hosting.eu 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User : u390967363 ( 390967363)
PHP Version : 8.2.30
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Directory :  /home/u390967363/domains/aibenproperties.com/public_html/app/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/u390967363/domains/aibenproperties.com/public_html/app/client-edit.php
<?php 
require 'includes/header.php'; 

$id = $_GET['id'] ?? null;
if (!$id) {
    header("Location: clients.php");
    exit;
}

$error = '';
$success = '';

// Fetch existing data
try {
    $stmt = $pdo->prepare("SELECT * FROM clients WHERE id = ?");
    $stmt->execute([$id]);
    $client = $stmt->fetch();
    
    if (!$client) {
        echo "Client not found.";
        exit;
    }
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
    exit;
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $first_name = $_POST['first_name'] ?? '';
    $last_name = $_POST['last_name'] ?? '';
    $email = $_POST['email'] ?? '';
    $phone = $_POST['phone'] ?? '';
    $status = $_POST['status'] ?? 'active';

    if ($first_name && $last_name && $email) {
        try {
            $stmt = $pdo->prepare("UPDATE clients SET first_name=?, last_name=?, email=?, phone=?, status=?, updated_at=NOW() WHERE id=?");
            $stmt->execute([$first_name, $last_name, $email, $phone, $status, $id]);
            $success = "Client updated successfully!";
            echo "<script>window.location.href='clients.php';</script>";
            exit;
        } catch (Exception $e) {
            $error = "Error updating client: " . $e->getMessage();
        }
    } else {
        $error = "First Name, Last Name, and Email are required.";
    }
}
?>

<div class="card">
    <h2>Edit Client</h2>
    
    <?php if ($error): ?>
        <p style="color: red;"><?= $error ?></p>
    <?php endif; ?>

    <form method="POST">
        <div style="display: flex; gap: 1rem;">
            <div class="form-group" style="flex: 1;">
                <label>First Name</label>
                <input type="text" name="first_name" class="form-control" value="<?= htmlspecialchars($client['first_name']) ?>" required>
            </div>
            <div class="form-group" style="flex: 1;">
                <label>Last Name</label>
                <input type="text" name="last_name" class="form-control" value="<?= htmlspecialchars($client['last_name']) ?>" required>
            </div>
        </div>
        
        <div style="display: flex; gap: 1rem;">
            <div class="form-group" style="flex: 1;">
                <label>Email</label>
                <input type="email" name="email" class="form-control" value="<?= htmlspecialchars($client['email']) ?>" required>
            </div>
            <div class="form-group" style="flex: 1;">
                <label>Phone</label>
                <input type="text" name="phone" class="form-control" value="<?= htmlspecialchars($client['phone']) ?>" required>
            </div>
        </div>

        <div class="form-group">
            <label>Status</label>
            <select name="status" class="form-control">
                <option value="active" <?= $client['status'] == 'active' ? 'selected' : '' ?>>Active</option>
                <option value="inactive" <?= $client['status'] == 'inactive' ? 'selected' : '' ?>>Inactive</option>
                <option value="lead" <?= $client['status'] == 'lead' ? 'selected' : '' ?>>Lead</option>
            </select>
        </div>

        <button type="submit" class="btn btn-primary">Update Client</button>
        <a href="clients.php" class="btn" style="background: #ddd;">Cancel</a>
    </form>
</div>

<?php require 'includes/footer.php'; ?>

Hry