81 lines
2.9 KiB
PHP
81 lines
2.9 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'templates/header.php';
|
|
|
|
$name = $price = $features = "";
|
|
$errors = [];
|
|
|
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
|
$name = trim($_POST["name"]);
|
|
$price = trim($_POST["price"]);
|
|
$features = trim($_POST["features"]);
|
|
|
|
if (empty($name)) {
|
|
$errors[] = "Plan name is required.";
|
|
}
|
|
if (empty($price) || !is_numeric($price)) {
|
|
$errors[] = "A valid price is required.";
|
|
}
|
|
|
|
if (empty($errors)) {
|
|
try {
|
|
$pdo = db();
|
|
$sql = "INSERT INTO plans (name, price, features, created_at) VALUES (?, ?, ?, NOW())";
|
|
$stmt = $pdo->prepare($sql);
|
|
$stmt->execute([$name, $price, $features]);
|
|
header("Location: plans.php");
|
|
exit;
|
|
} catch (PDOException $e) {
|
|
$errors[] = "Database error: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
<div class="container-fluid px-4">
|
|
<h1 class="mt-4">Create New Plan</h1>
|
|
<ol class="breadcrumb mb-4">
|
|
<li class="breadcrumb-item"><a href="index.php">Dashboard</a></li>
|
|
<li class="breadcrumb-item"><a href="plans.php">Plans</a></li>
|
|
<li class="breadcrumb-item active">Create</li>
|
|
</ol>
|
|
|
|
<div class="card mb-4">
|
|
<div class="card-header">
|
|
<i class="fas fa-award me-1"></i>
|
|
New Plan Details
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (!empty($errors)): ?>
|
|
<div class="alert alert-danger">
|
|
<ul>
|
|
<?php foreach ($errors as $error): ?>
|
|
<li><?php echo htmlspecialchars($error); ?></li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form action="create_plan.php" method="post">
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Plan Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" value="<?php echo htmlspecialchars($name); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="price" class="form-label">Price ($ per month)</label>
|
|
<input type="number" step="0.01" class="form-control" id="price" name="price" value="<?php echo htmlspecialchars($price); ?>" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="features" class="form-label">Features (comma-separated)</label>
|
|
<textarea class="form-control" id="features" name="features" rows="3"><?php echo htmlspecialchars($features); ?></textarea>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Create Plan</button>
|
|
<a href="plans.php" class="btn btn-secondary">Cancel</a>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once 'templates/footer.php'; ?>
|