-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathupdate-list.php
205 lines (115 loc) · 4.43 KB
/
update-list.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
<?php
include('config/constants.php');
//Get the Current Values of Selected List
if(isset($_GET['list_id']))
{
//Get the List ID value
$list_id = $_GET['list_id'];
//Connect to 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());
//Query to Get the Values from Database
$sql = "SELECT * FROM tbl_lists WHERE list_id=$list_id";
//Execute Query
$res = mysqli_query($conn, $sql);
//CHekc whether the query executed successfully or not
if($res==true)
{
//Get the Value from Database
$row = mysqli_fetch_assoc($res); //Value is in array
//printing $row array
//print_r($row);
//Create Individual Variable to save the data
$list_name = $row['list_name'];
$list_description = $row['list_description'];
}
else
{
//Go Back to Manage List Page
header('location:'.SITEURL.'manage-list.php');
}
}
?>
<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>
<a class="btn-secondary" href="<?php echo SITEURL; ?>">Home</a>
<a class="btn-secondary" href="<?php echo SITEURL; ?>manage-list.php">Manage Lists</a>
<h3>Update List Page</h3>
<p>
<?php
//Check whether the session is set or not
if(isset($_SESSION['update_fail']))
{
echo $_SESSION['update_fail'];
unset($_SESSION['update_fail']);
}
?>
</p>
<form method="POST" action="">
<table class="tbl-half">
<tr>
<td>List Name: </td>
<td><input type="text" name="list_name" value="<?php echo $list_name; ?>" required="required" /></td>
</tr>
<tr>
<td>List Description: </td>
<td>
<textarea name="list_description">
<?php echo $list_description; ?>
</textarea>
</td>
</tr>
<tr>
<td><input class="btn-lg btn-primary" type="submit" name="submit" value="UPDATE" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
<?php
//Check whether the Update is Clicked or Not
if(isset($_POST['submit']))
{
//echo "Button Clicked";
//Get the Updated Values from our Form
$list_name = $_POST['list_name'];
$list_description = $_POST['list_description'];
//Connect Database
$conn2 = mysqli_connect(LOCALHOST, DB_USERNAME, DB_PASSWORD) or die(mysqli_error());
//SElect the Database
$db_select2 = mysqli_select_db($conn2, DB_NAME);
//QUERY to Update List
$sql2 = "UPDATE tbl_lists SET
list_name = '$list_name',
list_description = '$list_description'
WHERE list_id=$list_id
";
//Execute the Query
$res2 = mysqli_query($conn2, $sql2);
//Check whether the query executed successfully or not
if($res2==true)
{
//Update Successful
//SEt the Message
$_SESSION['update'] = "List Updated Successfully";
//Redirect to Manage List PAge
header('location:'.SITEURL.'manage-list.php');
}
else
{
//FAiled to Update
//SEt Session Message
$_SESSION['update_fail'] = "Failed to Update List";
//Redirect to the Update List PAge
header('location:'.SITEURL.'update-list.php?list_id='.$list_id);
}
}
?>