-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_task.php
More file actions
35 lines (30 loc) · 971 Bytes
/
Copy pathadd_task.php
File metadata and controls
35 lines (30 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
session_start();
require 'includes/db.php';
include 'includes/header.php';
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit();
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$task_name = $_POST['task_name'] ?? '';
if (!empty($task_name)) {
$user_id = $_SESSION['user_id'];
$stmt = $pdo->prepare("INSERT INTO tasks (task_name, user_id) VALUES (?, ?)");
$stmt->execute([$task_name, $user_id]);
header('Location: dashboard.php');
exit();
} else {
$error_message = "Task name cannot be empty.";
}
}
?>
<h2>Add New Task</h2>
<?php if (isset($error_message)): ?>
<p style="color: red;"><?php echo htmlspecialchars($error_message); ?></p>
<?php endif; ?>
<form method="post" action="add_task.php">
<input type="text" name="task_name" placeholder="Task Name" required><br>
<button type="submit">Add Task</button>
</form>
<?php include 'includes/footer.php'; ?>