-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_task.php
More file actions
47 lines (37 loc) · 1.2 KB
/
add_task.php
File metadata and controls
47 lines (37 loc) · 1.2 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
<?php
include 'db_connect.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$title = $_POST['title'];
$description = $_POST['description'];
// Prepare the SQL statement to prevent SQL injection
$stmt = $conn->prepare("INSERT INTO tasks (title, description, status) VALUES (?, ?, 'pending')");
$stmt->bind_param("ss", $title, $description);
if ($stmt->execute()) {
echo "New task created successfully.";
} else {
echo "Error: " . $stmt->error;
}
$stmt->close();
$conn->close();
// Redirect back to index.php after adding the task
header("Location: index.php");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Add Task</title>
<link rel="stylesheet" type="text/css" href="style.css"> <!-- Link to CSS -->
</head>
<body>
<h1>Add New Task</h1>
<form action="add_task.php" method="POST">
<input type="text" name="title" placeholder="Task title" required>
<textarea name="description" placeholder="Task description" required></textarea>
<button type="submit">Add Task</button>
</form>
<p><a href="index.php">Back to Task List</a></p>
</body>
</html>