35050-vm/add_contact.php
Flatlogic Bot b4397b355f Sfepro v1
2025-10-19 03:26:15 +00:00

77 lines
3.0 KiB
PHP

<?php
require_once 'db/config.php';
$success_message = '';
$error_message = '';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = trim($_POST['name']);
$company = trim($_POST['company']);
$email = trim($_POST['email']);
$phone = trim($_POST['phone']);
$source = trim($_POST['source']);
$tags = trim($_POST['tags']);
if (empty($name) || empty($email)) {
$error_message = "Name and Email are required fields.";
} else {
try {
$stmt = db()->prepare("INSERT INTO contacts (name, company, email, phone, source, tags) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->execute([$name, $company, $email, $phone, $source, $tags]);
header("Location: index.php?success=1");
exit();
} catch (PDOException $e) {
$error_message = "Error: " . $e->getMessage();
}
}
}
include 'header.php';
?>
<div class="row justify-content-center">
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h4 class="mb-0">Add New Contact</h4>
</div>
<div class="card-body">
<?php if ($error_message): ?>
<div class="alert alert-danger" role="alert">
<?php echo $error_message; ?>
</div>
<?php endif; ?>
<form action="add_contact.php" method="post">
<div class="mb-3">
<label for="name" class="form-label">Name <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="company" class="form-label">Company</label>
<input type="text" class="form-control" id="company" name="company">
</div>
<div class="mb-3">
<label for="email" class="form-label">Email <span class="text-danger">*</span></label>
<input type="email" class="form-control" id="email" name="email" required>
</div>
<div class="mb-3">
<label for="phone" class="form-label">Phone</label>
<input type="tel" class="form-control" id="phone" name="phone">
</div>
<div class="mb-3">
<label for="source" class="form-label">Source</label>
<input type="text" class="form-control" id="source" name="source">
</div>
<div class="mb-3">
<label for="tags" class="form-label">Tags (comma-separated)</label>
<input type="text" class="form-control" id="tags" name="tags">
</div>
<button type="submit" class="btn btn-primary w-100">Add Contact</button>
</form>
</div>
</div>
</div>
</div>
<?php include 'footer.php'; ?>