-
Notifications
You must be signed in to change notification settings - Fork 0
/
del_employee.php
69 lines (60 loc) · 1.66 KB
/
del_employee.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
<!-- Add new employees -->
<?php session_start(); ?>
<?php
if (!isset($_SESSION['Authencated']) || $_SESSION['Authencated'] != True) {
header("Location: index.php");
exit();
}
$dbservername = 'localhost';
$dbname = 'hw2';
$dbusername = 'root';
$dbpassword = '';
$delEmployee = "";
$delEmployeeErr = "";
try {
if (empty($_GET["delEmployee"])) {
throw new Exception("you are deleting nothing.");
}
else {
$delEmployee = $_GET["delEmployee"];
}
$account = $_SESSION['account'];
$shopname = $_SESSION['shopname'];
// check if account not exist / it's already an employee
$conn = new PDO("mysql:host=$dbservername;dbname=$dbname", $dbusername, $dbpassword);
# set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("DELETE FROM job WHERE
U_id = (select U_id from user where account=:delEmployee) and
S_id in (select S_id from shop where shopname=:shopname)");
$stmt->execute(array('delEmployee' => $delEmployee, 'shopname' => $shopname));
if (!empty($delEmployeeErr)) {
// sent error with session variables
$_SESSION['delEmployeeErr'] = $delEmployeeErr;
echo <<< EOT
<script>
window.location.replace("myshop.php");
</script>
EOT;
// header("location: myshop.php");
}
else {
echo <<< EOT
<script>
alert("Delete $delEmployee successfully!");
window.location.replace("myshop.php");
</script>
EOT;
}
} catch (Exception $e) {
$msg = $e->getMessage();
session_unset();
session_destroy();
echo <<< EOT
<script>
alert("$msg");
window.location.replace("myshop.php");
</script>
EOT;
}
?>