-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-task.php
More file actions
154 lines (118 loc) · 5.04 KB
/
add-task.php
File metadata and controls
154 lines (118 loc) · 5.04 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
include('config/constants.php');
?>
<html>
<head>
<title>Task Manager with PHP and MySQL</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div class="wrapper">
<h1>TASK MANAGER</h1>
<a class="btn-secondary" href="index.php">Home</a>
<h3>Add Task Page</h3>
<p>
<?php
if(isset($_SESSION['add_fail'])){
echo $_SESSION['add_fail'];
unset($_SESSION['add_fail']);
}
?>
</p>
<form method="POST" action="">
<table class="tbl-half">
<tr>
<td>Task Name: </td>
<td><input type="text" name="task_name" placeholder="Enter your Task Name" required="required" /></td>
</tr>
<tr>
<td>Task Description: </td>
<td><textarea name="task_description" placeholder="Enter Task Description"></textarea></td>
</tr>
<tr>
<td>Select List: </td>
<td>
<select name="list_id">
<?php
$conn = mysqli_connect(LOCALHOST, DB_USERNAME, DB_PASSWORD) or die(mysqli_error());
$db_select = mysqli_select_db($conn, DB_NAME) or die(mysqli_error());
$sql = "SELECT * FROM tbl_lists";
$res = mysqli_query($conn, $sql);
if($res==true)
{
$count_rows = mysqli_num_rows($res);
if($count_rows>0)
{
while($row=mysqli_fetch_assoc($res))
{
$list_id = $row['list_id'];
$list_name = $row['list_name'];
?>
<option value="<?php echo $list_id ?>"><?php echo $list_name; ?></option>
<?php
}
}
else
{
?>
<option value="0">None</option>p
<?php
}
}
?>
</select>
</td>
</tr>
<tr>
<td>Priority: </td>
<td>
<select name="priority">
<option value="High">High</option>
<option value="Medium">Medium</option>
<option value="Low">Low</option>
</select>
</td>
</tr>
<tr>
<td>Deadline: </td>
<td><input type="date" name="deadline" /></td>
</tr>
<tr>
<td><input class="btn-primary btn-lg" type="submit" name="submit" value="SAVE" /></td>
</tr>
</table>
</form>
</div>
</div>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$task_name = $_POST['task_name'];
$task_description = $_POST['task_description'];
$list_id = $_POST['list_id'];
$priority = $_POST['priority'];
$deadline = $_POST['deadline'];
$conn2 = mysqli_connect(LOCALHOST, DB_USERNAME, DB_PASSWORD) or die(mysqli_error());
$db_select2 = mysqli_select_db($conn2, DB_NAME) or die(mysqli_error());
$sql2 = "INSERT INTO tbl_tasks SET
task_name = '$task_name',
task_description = '$task_description',
list_id = $list_id,
priority = '$priority',
deadline = '$deadline'
";
$res2 = mysqli_query($conn2, $sql2);
if($res2==true)
{
$_SESSION['add'] = "Task Added Successfully.";
header('location:index.php');
}
else
{
$_SESSION['add_fail'] = "Failed to Add Task";
header('location:add-task.php');
}
}
?>