34972-vm/contact_form.php
Flatlogic Bot abcecf5b5a mak1
2025-10-15 14:43:05 +00:00

100 lines
3.8 KiB
PHP

<?php
require_once 'db/config.php';
$name = '';
$email = '';
$id = null;
$is_edit = false;
if (isset($_GET['id'])) {
$id = $_GET['id'];
$is_edit = true;
$stmt = db()->prepare('SELECT * FROM contacts WHERE id = ?');
$stmt->execute([$id]);
$contact = $stmt->fetch();
if ($contact) {
$name = $contact['name'];
$email = $contact['email'];
} else {
die('Contact not found.');
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'] ?? '';
$email = $_POST['email'] ?? '';
if (empty($name) || empty($email)) {
$error = 'Name and email are required.';
} else {
if ($is_edit) {
$stmt = db()->prepare('UPDATE contacts SET name = ?, email = ? WHERE id = ?');
$stmt->execute([$name, $email, $id]);
} else {
$stmt = db()->prepare('INSERT INTO contacts (name, email) VALUES (?, ?)');
$stmt->execute([$name, $email]);
}
header('Location: contacts.php');
exit;
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= $is_edit ? 'Edit' : 'Add' ?> Contact - Makizto</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">
</head>
<body>
<div class="sidebar">
<h3>Makizto</h3>
<nav class="nav flex-column">
<a class="nav-link" href="index.php"><i data-feather="home" class="me-2"></i>Dashboard</a>
<a class="nav-link active" href="contacts.php"><i data-feather="users" class="me-2"></i>Contacts</a>
<a class="nav-link" href="deals.php"><i data-feather="dollar-sign" class="me-2"></i>Deals</a>
</nav>
</div>
<div class="main-content">
<div class="container-fluid">
<h1 class="h2 mb-4"><?= $is_edit ? 'Edit' : 'Add' ?> Contact</h1>
<?php if (isset($error)): ?>
<div class="alert alert-danger"><?= $error ?></div>
<?php endif; ?>
<div class="card">
<div class="card-body">
<form action="contact_form.php<?= $is_edit ? '?id=' . $id : '' ?>" method="post">
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" name="name" value="<?= htmlspecialchars($name) ?>" required>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="email" class="form-control" id="email" name="email" value="<?= htmlspecialchars($email) ?>" required>
</div>
<button type="submit" class="btn btn-primary"><?= $is_edit ? 'Update' : 'Create' ?> Contact</button>
<a href="contacts.php" class="btn btn-secondary">Cancel</a>
</form>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
<script>
feather.replace()
</script>
<script src="assets/js/main.js?v=<?php echo time(); ?>"></script>
</body>
</html>