-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathaddEmployee_process.php
91 lines (70 loc) · 2.59 KB
/
addEmployee_process.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
<?php
session_start();
$mysqli = new mysqli('localhost', 'root', '', 'supplier') or die(mysqli_error($mysqli));
$update = false;
$id = 0;
$EmpId = '';
$FirstName = '';
$LastName = '';
$UserName = '';
$Email = '';
$NICNumber = '';
$Address = '';
$PhoneNumber = '';
$Password = '';
if(isset($_POST['REGISTER'])){
$EmpId = $_POST['EmpId'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$UserName = $_POST['UserName'];
$Email = $_POST['Email'];
$NICNumber = $_POST['NICNumber'];
$Address = $_POST['Address'];
$PhoneNumber = $_POST['PhoneNumber'];
$Password = $_POST['Password'];
$mysqli->query("INSERT INTO employee (EmpId, FirstName, LastName, UserName, Email, NICNumber, Address, PhoneNumber, Password) VALUES('$EmpId', '$FirstName', '$LastName', '$UserName', '$Email', '$NICNumber', '$Address', '$PhoneNumber', '$Password')") or die($mysqli->error);
$_SESSION['message'] = "Record has been saved!";
$_SESSION['msg_type'] = "success";
header("location: addEmployee.php");
}
if (isset($_GET['delete'])){
$id = $_GET['delete'];
$mysqli->query("DELETE from employee WHERE id=$id") or die($mysqli->error());
$_SESSION['message'] = "Record has been deleted!";
$_SESSION['msg_type'] = "danger";
header("location: addEmployee.php");
}
if (isset($_GET['edit'])){
$id = $_GET['edit'];
$update = true;
$result = $mysqli->query("SELECT * FROM employee WHERE id='$id'") or die($mysqli->error());
if (count($result)==1){
$row = $result->fetch_array();
$EmpId = $row['EmpId'];
$FirstName = $row['FirstName'];
$LastName = $row['LastName'];
$UserName = $row['UserName'];
$Email = $row['Email'];
$NICNumber = $row['NICNumber'];
$Address = $row['Address'];
$PhoneNumber = $row['PhoneNumber'];
$Password = $row['Password'];
}
}
if(isset($_POST['UPDATE'])){
$id = $_POST['id'];
$EmpId = $_POST['EmpId'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$UserName = $_POST['UserName'];
$Email = $_POST['Email'];
$NICNumber = $_POST['NICNumber'];
$Address = $_POST['Address'];
$PhoneNumber = $_POST['PhoneNumber'];
$Password = $_POST['Password'];
$mysqli->query("UPDATE employee SET EmpId='$EmpId', FirstName='$FirstName', LastName='$LastName', UserName='$UserName', Email='$Email', NICNumber='$NICNumber', Address='$Address', PhoneNumber='$PhoneNumber', Password='$Password' WHERE id='$id'") or die($mysqli->error);
$_SESSION['message'] = "Record has been updateed!";
$_SESSION['msg_type'] = "warning";
header('location: addEmployee.php');
}
?>