36018-vm/post-task.php
Flatlogic Bot 893c62c0ac 77
2025-11-22 14:20:01 +00:00

66 lines
2.6 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 = 'error_task_required_fields';
} 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_new_task_title') ?></h1>
<form action="post-task.php" method="POST" class="mt-4 p-4 border rounded bg-light">
<?php if ($error): ?>
<div class="alert alert-danger"><?= __($error) ?></div>
<?php endif; ?>
<div class="mb-3">
<label for="title" class="form-label"><?= __('task_title_label') ?></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') ?></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') ?></label>
<input type="text" class="form-control" id="category" name="category">
</div>
<div class="mb-3">
<label for="location" class="form-label"><?= __('location_label') ?></label>
<input type="text" class="form-control" id="location" name="location">
</div>
<div class="mb-3">
<label for="payout" class="form-label"><?= __('payout_label') ?></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') ?></button>
</form>
</div>
<?php require_once 'shared/footer.php'; ?>