-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodify_employee_info.php
More file actions
255 lines (242 loc) · 5.69 KB
/
Copy pathmodify_employee_info.php
File metadata and controls
255 lines (242 loc) · 5.69 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
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
require_once('mysql_conn.php');
$sql1 ="SELECT * FROM department";
$result1 = mysql_query($sql1);
$sql2 ="SELECT * FROM login";
$result2 = mysql_query($sql2);
$msg="";
$errmsg="";
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$id="";
$setEID="";
$sql ="SELECT * FROM employee";
$result = mysql_query($sql);
$sname=mysql_escape_string($_REQUEST['sname']);
while($row = mysql_fetch_array($result))
{
$e_id= $row['e_id'];
if($sname == $e_id)
{
$setName = $row['name'];
$setDept = $row['dept'];
$setSal = $row['salary'];
$setGen = $row['gender'];
$setDOB = $row['dob'];
$setPhn = $row['phone'];
$setAdrs = $row['address'];
$setEID = $row['e_id'];
while($row2 = mysql_fetch_array($result2))
{
$e_id2= $row2['uname'];
if($sname == $e_id2)
{
$setPass = $row2['pass'];
}
}
}
}
$id=$setEID;
if($sname==$id)
{ $name = $_REQUEST['ename'];
$eid = mysql_escape_string($_REQUEST['eid']);
// && !preg_match('/^ *$/', $name)
if($_REQUEST['doption'] == "Update Employee Info")
{
$dept = $_REQUEST['dtype'];
$sal = $_REQUEST['sal'];
$name = $_REQUEST['ename'];
$date = $_REQUEST['date'];
$gender = $_REQUEST['gname'];
$phone = $_REQUEST['phone'];
$address = $_REQUEST['address'];
$password = mysql_escape_string($_REQUEST['pass']);
$query = mysql_query("SELECT * FROM `employee` WHERE e_id='$eid'");
$nn = mysql_num_rows($query);
if($nn != 0)
{
$sql4 = "UPDATE `employee` SET `name`='$name',`dept`='$dept',`salary`='$sal',`phone`='$phone',`gender`='$gender',`dob`='$date',`address`='$address' WHERE e_id='$eid'";
if(!mysql_query($sql4))
{
echo "Error in employee: " . $sql4. "<br>" . mysql_error($conn);
}
$sql3 ="UPDATE `login` SET `uname`='$eid',`pass`='$password',`acctype`='Employee' WHERE uname='$eid'";
if(!mysql_query($sql3))
{
echo "Error in login: " . $sql3 . "<br>" . mysql_error($conn);
}
else
{
$msg= 'Data Successfully Updated';
$setName="";
$setDept ="";
$setSal = "";
$setGen = "";
$setDOB = "";
$setPhn = "";
$setAdrs = "";
$setEID = "";
$setPass ="";
}
}
/*else
echo 'Employee ID already exist';*/
}
else if($_REQUEST['doption'] == "Remove Employee Info")
{
$usql= "DELETE FROM `salary` WHERE e_id='$eid'";
if(!mysql_query($usql))
{
echo "Error: " . $usql . "<br>" . mysql_error($conn);
}
$usql= "DELETE FROM `attendance` WHERE e_id='$eid'";
if(!mysql_query($usql))
{
echo "Error: " . $usql . "<br>" . mysql_error($conn);
}
$usql= "DELETE FROM `employee` WHERE e_id='$eid'";
if(!mysql_query($usql))
{
echo "Error: " . $usql . "<br>" . mysql_error($conn);
}
$usql= "DELETE FROM `login` WHERE uname='$eid'";
if(!mysql_query($usql))
{
echo "Error: " . $usql . "<br>" . mysql_error($conn);
}
else
{
$msg= "Successfully Deleted";
$setName="";
$setDept ="";
$setSal = "";
$setGen = "";
$setDOB = "";
$setPhn = "";
$setAdrs = "";
$setEID = "";
$setPass ="";
}
}
}
else
{
$errmsg = "ID not found";
$setName="";
$setDept ="";
$setSal ="";
$setGen = "";
$setDOB = "";
$setPhn = "";
$setAdrs = "";
$setEID = "";
$setPass ="";
}
}
else
{
$setName="";
$setDept ="";
$setSal ="";
$setGen = "";
$setDOB = "";
$setPhn = "";
$setAdrs = "";
$setEID = "";
$setPass ="";
}
?>
<html>
<head><title>For Modifying & Sacking Employee.</title></head>
<center>
<h1>Modify/Remove Employee Info</h1>
<hr>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ?>" method="POST">
<table>
<tr>
<th>Search Employee: </th>
<td><input type="text" name="sname"></td>
</tr>
<tr>
<th> </th>
<td><input type="submit" name="submit" value="Search"></td>
</tr>
<tr>
<th>Name: </th>
<td><input type="text" name="ename" value="<?php echo $setName ?>">
</td>
</tr>
<tr>
<th>Current Department: </th>
<td><input type="text" name="dname" value="<?php echo $setDept ?>" disabled>
</td>
</tr>
<tr>
<th>Change Department: </th>
<td><select name="dtype">
<?php
while ($row1 = mysql_fetch_assoc($result1))
{
echo '<option value="'.$row1['dept_name'].'">'.$row1['dept_name'].'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<th>Gender: </th>
<td><input type="text" name="gname" value="<?php echo $setGen ?>">
</td>
</tr>
<tr>
<th>Date of Birth: </th>
<td><input type="date" name="date" value="<?php echo $setDOB ?>">
</td>
</tr>
<tr>
<th>Phone: </th>
<td><input type="text" name="phone" value="<?php echo $setPhn ?>">
</td>
</tr>
<tr>
<th>Address: </th>
<td><textarea rows='3' cols='30' name="address"><?php echo $setAdrs ?></textarea>
</td>
</tr>
<tr>
<th>Monthly Salary: </th>
<td><input type="text" name="sal" value="<?php echo $setSal ?>">
</td>
</tr>
<tr>
<th>Employee ID: </th>
<td><input type="text" name="eid" value="<?php echo $setEID ?>">
</td>
</tr>
<tr>
<th>Password: </th>
<td><input type="text" name="pass" value="<?php echo $setPass ?>">
</td>
</tr>
<tr>
<th>Select an Option: </th>
<td><select name="doption">
<option>Update Employee Info</option>
<option>Remove Employee Info</option>
</select>
</td>
</tr>
<tr>
<th> </th>
<td>
<input type="submit" name="submit" value="Submit">
<p style="color:green"><?php echo $msg; ?></p>
<p style="color:red"><?php echo $errmsg; ?></p>
</td>
</tr>
</table>
</form>
<a href="manager.php">Back to admin page</a>
<a href="logout.php"><h3>Logout</h3></a>
</center>
</html>