-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertst.php
More file actions
140 lines (122 loc) · 4.03 KB
/
insertst.php
File metadata and controls
140 lines (122 loc) · 4.03 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
<!DOCTYPE html>
<html>
<head>
<title>Insert Staff details</title>
<link rel="stylesheet" type="text/css" href="insertd.css">
</head>
<body>
<div class="Menu">
<ul>
<li><a class="active" href="process.php">Home</a></li>
<li><a href="insert.php">Insert</a></li>
<li><a href="update.php">Update</a></li>
<li><a href="delete.php">Delete</a></li>
<li><a href="peek.php">Peek</a></li>
</ul>
</div>
<div class = "loginbox" style="margin-top: 20%; height: 950px;">
<img src="p2.png" class="avatar">
<h1>Staff Registration</h1>
<form action="#" method="POST">
<p>First name</p>
<input type="text" name="FName" placeholder="Enter First Name">
<p>Last name</p>
<input type="text" name="LName" placeholder="Enter Last Name">
<p>Phone number</p>
<input type="text" name="phoneNo" placeholder="9999999999">
<p>Gender</p><br>
<input type="radio" name="gender" value="male" id="gender" > <font size="2">Male</font><br>
<input type="radio" name="gender" value="female" id="gender" > <font size="2">Female</font><br>
<input type="radio" name="gender" value="other" id="gender" > <font size="2">Other</font>
<br>
<br>
<p>Department alloted</p>
<input type="text" name="DepartmentAllotted" placeholder="Canteen">
<p>Salary</p>
<input type="number" name="salary" placeholder="10000">
<p>Username</p>
<input type="text" name="username" placeholder="Hogwarts123">
<p>Enter password</p>
<input type="password" name="password1" placeholder="Enter Password">
<p>Re-enter password</p>
<input type="password" name="password2" placeholder="Enter Password">
<input type="Submit" name="submit" value="Submit">
</form>
</div>
<div class = "logout">
<a href="login.php">
<img src="p3.png" alt="Logout" style="width:50px;height:42px;border:0;position: fixed;top: 8px;right: 16px;font-size: 18px; position: fixed;">
</a>
</div>
</body>
</html>
<?php
$host = "localhost";
$user="root";
$password="";
$db="Hogwarts";
$con=mysqli_connect("localhost","root","","Hogwarts");
if($con === false)
{
echo "Connection failed to establish";
}
mysqli_select_db($con,$db);
//$result = mysqli_query($con,$sql);
// if($result)
//{
// echo "new record is inserted successfully";
//}
if(isset($_POST['FName']) && isset($_POST['LName']) && isset($_POST['phoneNo']) && isset($_POST['gender']) && isset($_POST['username']) && isset($_POST['password1']) && isset($_POST['password2']))
{
//entering
$Fname=$_POST['FName'];
$Lname=$_POST['LName'];
$phoneNo=$_POST['phoneNo'];
if($_POST['gender']=="female"){
$gender="f";
}
elseif ($_POST['gender']=="male") {
$gender="m";
}
else{
$gender="o";
}
$deptAlloted=isset($_POST['DepartmentAllotted']) ? $_POST['DepartmentAllotted'] : ' ';
$salary=$_POST['salary'];
$username=$_POST['username'];
$password1=$_POST['password1'];
$password2=$_POST['password2'];
$sql = "select * from Hogwarts.login where uname='".$username."'";
$result=mysqli_query($con,$sql);
if (mysqli_num_rows($result)==1)
{
echo "Username Already exists.";
}
else
{
if($password2==$password1)
{
$sql = "INSERT INTO `login`(`uname`, `pass`, `SchoolID`) VALUES ('$username','$password1',0)";
$result = mysqli_query($con,$sql);
$sql = "INSERT INTO `Staff`(`fname`, `lname`, `phoneNo`, `gender`, `deptAlloted`, `salary`, `username`) VALUES ('$Fname','$Lname','$phoneNo','$gender','$deptAlloted',$salary,'$username')";
$result = mysqli_query($con,$sql);
$sql="SELECT `id` FROM `Staff` WHERE username = '$username'";
$result = $con->query($sql);
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
$Tid=$row['id'];
}
}
$sql="UPDATE login SET SchoolID=$Tid where uname = '$username'";
$result= mysqli_query($con,$sql);
if($result)
{
?> <div style= "width:50px;height:42px;border:0;position: fixed;top: 20%; left: 3%;font-size: 18px;">
<font color="white"><?php echo "Record inserted successfully";?></font></div><?php
}
}
}
}
?>