-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_department.php
66 lines (62 loc) · 1.43 KB
/
add_department.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
<?php
session_start();
if (!isset($_SESSION["manager"])) {
header('Location: index.php');
exit;
}
require_once('mysql_conn.php');
$msg = "";
$msg1 = "";
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$dname= $_POST['dname'];
$sql ="SELECT * FROM department";
$result = mysql_query($sql);
$verify = "";
while ($row = mysql_fetch_array($result))
{
$sdept = $row['dept_name'];
if($sdept==$dname)
{
$verify="found";
}
}
//echo preg_match('/^ *$/', $dname);
if($verify != "found" && !preg_match('/^ *$/', $dname))
{
$sql1 ="INSERT INTO `department` (dept_name)
VALUES ('$dname')";
if(!mysql_query($sql1))
{
echo "Error in login: " . $sql1 . "<br>" . mysql_error($conn);
}
else
$msg= 'Department Added';
}
else
$msg1='Invalid input or Department already exist';
}
?>
<html>
<head><title>For Adding Department</title></head>
<center>
<h1> Add New Department</h1>
<hr>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]) ?>" method="POST">
<table>
<tr>
<th>Department Name: </th>
<td><input type="text" name="dname"></td>
</tr>
<tr>
<th> </th>
<td><input type="submit" name="submit" value="AddDept."></td>
</tr>
</table>
</form>
<p style="color:green"><?php echo $msg; ?></p>
<p style="color:red"><?php echo $msg1; ?></p>
<a href="manager.php">Back to admin page</a>
<a href="logout.php"><h3>Logout</h3></a>
</center>
</html>