-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_task.php
More file actions
71 lines (60 loc) · 1.74 KB
/
create_task.php
File metadata and controls
71 lines (60 loc) · 1.74 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
session_start();
require_once 'config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$title = trim($_POST['title']);
$due_date = $_POST['due_date'];
$user_id = $_SESSION['user_id'];
if (empty($title) || empty($due_date)) {
$error = "Please fill in all fields.";
} else {
try {
$stmt = $pdo->prepare("INSERT INTO tasks (user_id, title, due_date) VALUES (:user_id, :title, :due_date)");
$stmt->execute([
'user_id' => $user_id,
'title' => $title,
'due_date' => $due_date
]);
header("Location: task.php");
exit;
} catch (PDOException $e) {
$error = "Database Error: " . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Create Task</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="navbar">
<div class="nav-left">
<a href="index.php">Task Manager</a>
</div>
<div class="nav-right">
<a href="task.php">Back to Tasks</a>
<a href="logout.php">Logout</a>
</div>
</div>
<div class="container">
<h2>Create New Task</h2>
<?php if (isset($error)): ?>
<p class="error"><?php echo htmlspecialchars($error); ?></p>
<?php endif; ?>
<form method="POST" action="create_task.php">
<label for="title">Task Title:</label><br>
<input type="text" id="title" name="title" required><br><br>
<label for="due_date">Due Date:</label><br>
<input type="date" id="due_date" name="due_date" required><br><br>
<button type="submit">Create Task</button>
</form>
</div>
</body>
</html>