-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathupdate-task.php
270 lines (181 loc) · 7.97 KB
/
update-task.php
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<?php
include('config/constants.php');
//Check the Task ID in URL
if(isset($_GET['task_id']))
{
//Get the Values from DAtabase
$task_id = $_GET['task_id'];
//Connect Database
$conn = mysqli_connect(LOCALHOST, DB_USERNAME, DB_PASSWORD) or die(mysqli_error());
//Select Database
$db_select = mysqli_select_db($conn, DB_NAME) or die(mysqli_error());
//SQL Query to Get the detail of selected task
$sql = "SELECT * FROM tbl_tasks WHERE task_id=$task_id";
//Execute Query
$res = mysqli_query($conn, $sql);
//Check if the query executed successfully or not
if($res==true)
{
//Query <br />Executed
$row = mysqli_fetch_assoc($res);
//Get the Individual Value
$task_name = $row['task_name'];
$task_description = $row['task_description'];
$list_id = $row['list_id'];
$priority = $row['priority'];
$deadline = $row['deadline'];
}
}
else
{
//Redirect to Homepage
header('location:'.SITEURL);
}
?>
<html>
<head>
<title>Task Manager with PHP and MySQL</title>
<link rel="stylesheet" href="<?php echo SITEURL; ?>css/style.css" />
</head>
<body>
<div class="wrapper">
<h1>TASK MANAGER</h1>
<p>
<a class="btn-secondary" href="<?php echo SITEURL; ?>">Home</a>
</p>
<h3>Update Task Page</h3>
<p>
<?php
if(isset($_SESSION['update_fail']))
{
echo $_SESSION['update_fail'];
unset($_SESSION['update_fail']);
}
?>
</p>
<form method="POST" action="">
<table class="tbl-half">
<tr>
<td>Task Name: </td>
<td><input type="text" name="task_name" value="<?php echo $task_name; ?>" required="required" /></td>
</tr>
<tr>
<td>Task Description: </td>
<td>
<textarea name="task_description">
<?php echo $task_description; ?>
</textarea>
</td>
</tr>
<tr>
<td>Select List: </td>
<td>
<select name="list_id">
<?php
//Connect Database
$conn2 = mysqli_connect(LOCALHOST, DB_USERNAME, DB_PASSWORD) or die(mysqli_error());
//SElect Database
$db_select2 = mysqli_select_db($conn2, DB_NAME) or die(mysqli_error());
//SQL Query to GET Lists
$sql2 = "SELECT * FROM tbl_lists";
//Execute Query
$res2 = mysqli_query($conn2, $sql2);
//Check if executed successfully or not
if($res2==true)
{
//Display the Lists
//Count Rows
$count_rows2 = mysqli_num_rows($res2);
//Check whether list is added or not
if($count_rows2>0)
{
//Lists are Added
while($row2=mysqli_fetch_assoc($res2))
{
//Get individual value
$list_id_db = $row2['list_id'];
$list_name = $row2['list_name'];
?>
<option <?php if($list_id_db==$list_id){echo "selected='selected'";} ?> value="<?php echo $list_id_db; ?>"><?php echo $list_name; ?></option>
<?php
}
}
else
{
//No List Added
//Display None as option
?>
<option <?php if($list_id=0){echo "selected='selected'";} ?> value="0">None</option>p
<?php
}
}
?>
</select>
</td>
</tr>
<tr>
<td>Priority: </td>
<td>
<select name="priority">
<option <?php if($priority=="High"){echo "selected='selected'";} ?> value="High">High</option>
<option <?php if($priority=="Medium"){echo "selected='selected'";} ?> value="Medium">Medium</option>
<option <?php if($priority=="Low"){echo "selected='selected'";} ?> value="Low">Low</option>
</select>
</td>
</tr>
<tr>
<td>Deadline: </td>
<td><input type="date" name="deadline" value="<?php echo $deadline; ?>" /></td>
</tr>
<tr>
<td><input class="btn-primary btn-lg" type="submit" name="submit" value="UPDATE" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
//Check if the button is clicked
if(isset($_POST['submit']))
{
//echo "Clicked";
//Get the CAlues from Form
$task_name = $_POST['task_name'];
$task_description = $_POST['task_description'];
$list_id = $_POST['list_id'];
$priority = $_POST['priority'];
$deadline = $_POST['deadline'];
//Connect Database
$conn3 = mysqli_connect(LOCALHOST, DB_USERNAME, DB_PASSWORD) or die(mysqli_error());
//SElect Database
$db_select3 = mysqli_select_db($conn3, DB_NAME) or die(mysqli_error());
//CREATE SQL QUery to Update TAsk
$sql3 = "UPDATE tbl_tasks SET
task_name = '$task_name',
task_description = '$task_description',
list_id = '$list_id',
priority = '$priority',
deadline = '$deadline'
WHERE
task_id = $task_id
";
//Execute Query
$res3 = mysqli_query($conn3, $sql3);
//CHeck whether the Query Executed of Not
if($res3==true)
{
//Query Executed and Task Updated
$_SESSION['update'] = "Task Updated Successfully.";
//Redirect to Home Page
header('location:'.SITEURL);
}
else
{
//FAiled to Update Task
$_SESSION['update_fail'] = "Failed to Update Task";
//Redirect to this Page
header('location:'.SITEURL.'update-task.php?task_id='.$task_id);
}
}
?>