-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent.php
282 lines (274 loc) · 7.19 KB
/
student.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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?php
include("header.php");
if($_POST[setid] == $_SESSION[setid])
{
if(isset($_POST[submit]))
{
if(isset($_GET[regno]) || isset($_SESSION[regno]))
{
if(isset($_GET[regno]))
{
$regno = $_GET[regno];
}
else
{
$regno = $_SESSION[regno];
}
$sql="UPDATE students SET password=$_POST[npassword], name=$_POST[name], dob=$_POST[dateofbirth], address=$_POST[address], contactnumber=$_POST[contactnumber], courseid=$_POST[course], status=$_POST[status], createdat=$text,regno=$_POST[regno] WHERE regno=$regno";
if (!mysqli_query($con,$sql))
{
die(Error: . mysqli_error($con));
}
else
{
$res = "<font color=green>1 record updated</font>";
$resi=1;
}
}
else
{
$text=date("Y-m-d");
$sql="INSERT INTO students (regno,password, name, dob, address, contactnumber, createdat, courseid, status) VALUES ($_POST[regno], $_POST[npassword], $_POST[name], $_POST[dateofbirth], $_POST[address], $_POST[contactnumber], $text, $_POST[course], $_POST[status])";
if(!mysqli_query($con,$sql))
{
die(Error: . mysqli_error($con));
}
else
{
$res = "One record is added";
$resi = 1;
}
}
}
}
$_SESSION[setid]=rand();
if(isset($_SESSION[regno]))
{
$sql="SELECT * FROM students where regno=$_SESSION[regno]";
}
else
{
$sql="SELECT * FROM students where regno=$_GET[regno]";
}
$qres= mysqli_query($con,$sql);
$rs = mysqli_fetch_array($qres);
?>
<div class="slider_top2">
<h2>Student profile</h2>
</div>
<div class="clr"></div>
<div class="body_resize">
<div class="body">
<div class="full">
<form name="formname" method=post action="" onsubmit="return validation()">
<input type="hidden" name="setid" value="<?php echo $_SESSION[setid]; ?>" />
<table class="tftable" width="530" border="1">
<?php
if($resi==1)
{
echo "<tr> <th colspan=2> $res</th> </tr>";
}
?>
<tr>
<th width="220" scope="col">Name</th>
<td width="294" scope="col">
<input name="name" type="text" id="name" value="<?php echo $rs[name]; ?>" placeholder="Enter Name" size="25"/></td> </th>
</tr>
<tr>
<th scope="row">Registration No.</th>
<td>
<?php
if(isset($_GET[regno]))
{
?>
<input type="text" name="regno" id="regno" value="<?php echo $rs[regno]; ?>" placeholder="Enter Registration Number" size="25" readonly style="background-color: yellow;" />
<?php
}
else
{
?>
<input type="text" name="regno" id="regno" value="<?php echo $rs[regno]; ?>" placeholder="Enter Registration Number" size="25"/>
<?php
}
?>
</td> </th>
</tr></td>
</tr>
<tr>
<th scope="row">New Password</th>
<td><input type="password" name="npassword" id="npassword" value="<?php echo $rs[password]; ?>" placeholder="Enter New Password " size="25"/></td> </th>
</tr> </td>
</tr>
<tr>
<th scope="row">Confirm password</th>
<td><input type="password" name="cpassword" id="cpassword" value="<?php echo $rs[password]; ?>" placeholder="Enter Confirm Password " size="25"/></td> </th>
</tr> </td>
</tr>
<tr>
<th scope="row">Course</th>
<td>
<?php
$result = mysqli_query($con,"Select * from course where status=Enabled");
?>
<select name="course" id="course">
<option>Select</option>
<?php
while($rs1 = mysqli_fetch_array($result))
{ if($rs[courseid] == $rs1[courseid])
{
echo "<option value=$rs1[courseid] selected>$rs1[coursename]</option>";
}
else
{
echo "<option value=$rs1[courseid]>$rs1[coursename]</option>";
}
}
?>
</select>
</td>
</tr>
<tr>
<th scope="row">Dateofbirth</th>
<td><label for="date of birth"></label>
<input type="date" name="dateofbirth" id="dateofbirth" value="<?php echo $rs[dob]; ?>" /></td>
</tr>
<tr>
<th scope="row">Address</th>
<td><label for="address"></label>
<textarea name="address" id="address" cols="40" rows="5" placeholder="Enter Address" /><?php echo $rs[address]; ?></textarea></td>
</tr>
<tr>
<th scope="row">Contact Number </th>
<td><label for="contact number"></label>
<input type="text" name="contactnumber" id="contactnumber" value="<?php echo $rs[contactnumber]; ?>" placeholder="Enter Contact Number" size="25"/></td>
</tr>
<tr>
<th scope="row">Status
<label for="status"></label></th>
<td><label for="status"></label>
<select name="status" id="status">
<?php
$arr = array("Select","Enabled","Disabled");
foreach($arr as $value)
{
if($rs[status] == $value )
{
echo "<option value=$value selected>$value</option>";
}
else
{
echo "<option value=$value>$value</option>";
}
}
?>
</select></td>
</tr>
<tr>
<th colspan="2" scope="row"><input type="submit" name="submit" id="submit" value="Submit" /></th>
</tr>
</table>
</form>
<p> </p>
</div>
<div class="clr"></div>
</div>
</div>
<?php
include("footer.php");
?>
<script type="application/javascript">
function validation()
{
var alphaExp = /^[a-zA-Z\s]+$/;
if(formname.name.value=="")
{
alert("Please Enter Name...");
formname.name.focus();
return false;
}
else if(!formname.name.value.match(alphaExp)){
alert("Please enter valid character...");
formname.name.value = "";
formname.name.focus();
return false;
}
else if(formname.regno.value=="")
{
alert("Please Enter Registration Number...");
formname.regno.focus();
return false;
}
else if(isNaN(formname.regno.value))
{
alert("Registration number not valid..(Like : 201300210221)");
document.formname.regno.focus();
return false;
}
else if(formname.npassword.value=="")
{
alert("Please Enter New Password...");
formname.npassword.focus();
return false;
}
else if(formname.cpassword.value=="")
{
alert("Please Enter Confirm Password...");
formname.cpassword.focus();
return false;
}
else if(formname.cpassword.value!=formname.npassword.value)
{
alert("Password and confirm password not matching...");
formname.cpassword.value == "";
formname.npassword.value == "";
formname.cpassword.focus();
return false;
}
else if(formname.course.value=="Select")
{
alert("Please Enter Course...");
formname.course.focus();
return false;
}
else if(formname.dateofbirth.value=="")
{
alert("Please Enter Date Of Birth...");
formname.dateofbirth.focus();
return false;
}
else if(formname.address.value=="")
{
alert("Please Enter Address...");
formname.address.focus();
return false;
}
else if(formname.contactnumber.value=="")
{
alert("Please Enter Contact Number...");
formname.contactnumber.focus();
return false;
}
else if(isNaN(formname.contactnumber.value))
{
alert("Enter the valid Mobile Number(Like : 9566137117)");
formname.contactnumber.focus();
return false;
}
else if((formname.contactnumber.value.length < 9) || (formname.contactnumber.value.length > 11))
{
alert(" Your Mobile Number must be 1 to 10 Integers");
document.formname.contactnumber.select();
return false;
}
else if(formname.status.value=="Select")
{
alert("Please Enter Status...");
formname.status.focus();
return false;
}
else
{
return true;
}
}
</script>