63 lines
2.3 KiB
PHP
63 lines
2.3 KiB
PHP
<?php
|
|
require_once 'db/config.php';
|
|
require_once 'shared/header.php';
|
|
|
|
// Redirect if not logged in
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit();
|
|
}
|
|
|
|
$error = '';
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$title = $_POST['title'] ?? '';
|
|
$description = $_POST['description'] ?? '';
|
|
$category = $_POST['category'] ?? '';
|
|
$location = $_POST['location'] ?? '';
|
|
$payout = $_POST['payout'] ?? '';
|
|
$user_id = $_SESSION['user_id'];
|
|
|
|
if (empty($title) || empty($description) || empty($payout)) {
|
|
$error = 'Title, description, and payout are required.';
|
|
} else {
|
|
try {
|
|
$stmt = db()->prepare("INSERT INTO tasks (user_id, title, description, category, location, payout) VALUES (?, ?, ?, ?, ?, ?)");
|
|
$stmt->execute([$user_id, $title, $description, $category, $location, $payout]);
|
|
header('Location: index.php');
|
|
exit();
|
|
} catch (PDOException $e) {
|
|
$error = "Database error: " . $e->getMessage();
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
|
|
<div class="container">
|
|
<h1 class="text-center mt-5">Post a New Task</h1>
|
|
<form action="post-task.php" method="POST" class="mt-4 p-4 border rounded bg-light">
|
|
<div class="mb-3">
|
|
<label for="title" class="form-label">Task Title</label>
|
|
<input type="text" class="form-control" id="title" name="title" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="description" class="form-label">Description</label>
|
|
<textarea class="form-control" id="description" name="description" rows="3" required></textarea>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="category" class="form-label">Category</label>
|
|
<input type="text" class="form-control" id="category" name="category">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="location" class="form-label">Location</label>
|
|
<input type="text" class="form-control" id="location" name="location">
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="payout" class="form-label">Payout</label>
|
|
<input type="number" class="form-control" id="payout" name="payout" step="0.01" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary">Post Task</button>
|
|
</form>
|
|
</div>
|
|
|
|
<?php require_once 'shared/footer.php'; ?>
|