-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditstaff.php
More file actions
150 lines (126 loc) · 5.58 KB
/
editstaff.php
File metadata and controls
150 lines (126 loc) · 5.58 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
<!DOCTYPE HTML>
<html>
<head>
<title> Using staff details </title>
<link rel="stylesheet" href="style.css" />
</head>
<body bgcolor="white">
<h1> Staff Update / Insert </h1>
<?php
$formtop='<form <action="<?php echo htmlentities($_SERVER[$redir]); ?>" method="post">';
$menu=$formtop.'<select name="second" style="display: none"> <option value=""></option></select> <input type="text" name ="third" value="" style="display: none"';
$subbutton='<input type="submit" name="formSubmit" value="Submit" /></form>';
$formdetail="";
$query="";
$wherecond="";
$result_id="";
$Fname="";
$Lname="";
$Address="";
$Phone="";
$Salary="";
$SNO="";
$Position="";
$Innputform="";
if(isset($_POST['formSubmit'])) {$query= $_POST['first'];
$wherecond= $_POST['second'];
$Innputform=$_POST['third'];
if ($query && $Innputform){
$Fname=$_POST["FName"];
$Lname=$_POST["LName"];
$Address=$_POST["Address"];
$Phone=$_POST["Phone"];
$Salary=$_POST["Salary"];
$SNO=$_POST["Sno"];
$Bno=$_POST["Bno"];
$Position=$_POST["Position"];
}
}
$conn_id = @mysql_connect ("server", "id","password")
or exit ();
mysql_select_db ("Dreamhome_km32", $conn_id);
if (!$query && !$wherecond){
$formdetail.=$menu.'
<label for="first">Please choose how you like to search :</label><br>
<select name="first">
<option value="">Select an option...</option>
<option value="Update">Update</option>
<option value="Insert">Insert</option>
</select>
<br>'.$subbutton;
}
if ($query==="Update" && !$wherecond){
$result_id = mysql_query ("select FName, LName, Sno from staff") or exit ();
if ($result_id){
PrintF("<p>Please select Staff No : </p>");
$menu=$formtop.'<select name="first" style="display: none">
<option value='.$query.'></option>
</select> <input type="text" name ="third" value="" style="display: none"';
$menu.="<label for='second'> Search parameters : </label> <select name='second'><option value=''>Select staff member...</option>";
while ($row = mysql_fetch_array ($result_id)){
$menu.="<option value=".$row["Sno"].">".$row["FName"]." ".$row["LName"]." ".$row["Sno"]."</option>";
}
$menu.=$subbutton;
mysql_free_result ($result_id);
}
}
if ($query==="Update" && $wherecond){
$result_id = mysql_query ("select * from staff where Sno='".$wherecond."'") or exit ();
$formdetail=$formtop.'<select name="second" style="display: none"> <option value='.$wherecond.'></option></select>
<input type="text" name ="third" value="True" style="display: none">
<select name="first" style="display: none">
<option value='.$query.'></option>
</select>';
if ($result_id){
$row = mysql_fetch_assoc ($result_id);
printf($formdetail.
"<br> First Name : <input type='text' name ='FName' value=".$row["FName"]." readonly>".
"<br> Second Name : <input type='text' name ='LName' value=".$row["LName"]." readonly>".
"<br> Staff No. : <input type='text' name ='Sno' value=".$row["Sno"]." readonly>".
"<br> Address : <input type='text' name ='Address' value=".$row["Address"].">".
"<br> Telephone :<input type='text' name ='Phone' value=".$row["Tel_No"].">".
"<br> Position :<input type='text' name ='Position' value=".$row["Position"].">".
"<br> Branch Number :<input type='text' name ='Bno' value=".$row["Bno"].">".
"<br> Salary : <input type='text' name ='Salary' value=".$row["Salary"].">".$subbutton);
}
}
if ($query==="Insert" && !$Innputform){
$formdetail=$formtop.'<select name="second" style="display: none"> <option value=""></option></select>
<input type="text" name ="third" value="True" style="display: none">'
.'<select name="first" style="display: none">
<option value='.$query.'></option>
</select>';
printf($formdetail.
"<br> First Name : <input type='text' name ='FName' value='''>".
"<br> Second Name : <input type='text' name ='LName' value='''>".
"<br> Staff No. : <input type='text' name ='Sno' value='''>".
"<br> Address : <input type='text' name ='Address' value=''>".
"<br> Telephone :<input type='text' name ='Phone' value=''>".
"<br> Position :<input type='text' name ='Position' value=''>".
"<br> Branch Number :<input type='text' name ='Bno' value=''>".
"<br> Salary : <input type='text' name ='Salary' value=''>".$subbutton);
}
if ($Innputform){
$formdetail=$formtop.'<select name="second" style="display: none"> <option value=""></option></select>
<input type="text" name ="third" value="True" style="display: none" ><select name="first" style="display: none">
<option value=""></option> </select>';
if ($query==="Insert")
{ if( mysql_query ("Insert into staff (FName,LName,Sno,Address,Tel_No,Position,Salary,Bno) Values ('".$Fname."','".$Lname."','".$SNO."','".$Address."','".
$Phone."','".$Position."','".$Salary."','".$Bno."')")){
printf("Staff Inserted");
}
}
if ($query==="Update"){
if( mysql_query ("Update staff SET Address='".$Address."', Tel_No='".$Phone."', Position='".$Position."', Salary='".$Salary."' , Bno ='".$Bno."' where Sno='".$wherecond."'" ) ){
printf("Updated");}
else { printf("Failed update");}
}
$formdetail=$formtop.'<select name="second" style="display: none"> <option value=""></option></select>
<input type="text" name ="third" value="True" style="display: none" <select name="first" style="display: none">
<option value=""></option> </select><a href="index.html"> Back to index </a>';
}
?>
<span><?php printf( $formdetail); ?> </span>
<span><?php printf( $menu); ?> </span>
</body>
</html>