-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudentform.php
376 lines (352 loc) · 11.3 KB
/
studentform.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Student Forms</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://localhost/management/bootstrap/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Courgette" rel="stylesheet">
<script src="http://localhost/management/bootstrap/bootstrap.min.js"></script>
<style>
body{
font-family: Courgette;
}
.submit{
background-color: purple;
color:white;
text-size:24px;
padding: 6px;
border-radius: 5px;
border:1px solid white;
font-size: 24px;
}
.submit:hover{
background-color: white;
color: purple;
box-shadow: 0px 0px 20px white;
}
h1{
font-size: 14px;
}
td,th{
padding: 4px;
text-align: center;
}
</style>
</head>
<?php
$servername = "localhost";
$username="root";
$password="";
$dbname="hack";
$id="";
$name="";
$fname="";
$email="";
$phone="";
$state="";
$qualification="";
$branch="";
$rollno="";
$gender="";
$birth="birth";
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
//connect to mysql database
try{
$conn =mysqli_connect($servername,$username,$password,$dbname);
}catch(MySQLi_Sql_Exception $ex){
echo("error in connecting");
}
//get data from the form
function getData()
{
$data = array();
$data[1]=$_POST['name'];
$data[2]=$_POST['fname'];
$data[3]=$_POST['email'];
$data[4]=$_POST['phone'];
$data[5]=$_POST['state'];
$data[6]=$_POST['qualification'];
$data[7]=$_POST['branch'];
$data[8]=$_POST['rollno'];
$data[9]=$_POST['gender'];
$data[10]=$_POST['birth'];
return $data;
}
//search
if(isset($_POST['search']))
{
$info = getData();
$search_query="SELECT * FROM smash WHERE id = '$info[0]'";
$search_result=mysqli_query($conn, $search_query);
if($search_result)
{
if(mysqli_num_rows($search_result))
{
while($rows = mysqli_fetch_array($search_result))
{
$id = $rows['id'];
$name = $rows['name'];
$fname = $rows['fname'];
$email = $rows['email'];
$phone = $rows['phone'];
$state = $rows['state'];
$qualification = $rows['qualification'];
$branch = $rows['branch'];
$rollno = $rows['rollno'];
$gender = $rows['gender'];
$birth = $rows['birth'];
}
}else{
echo("no data are available");
}
} else{
echo("result error");
}
}
//insert
if(isset($_POST['insert'])){
$info = getData();
$insert_query="INSERT INTO `smash`(`name`, `fname`, `email`, `phone`,`state`,`qualification`,`branch`,`rollno`,`gender`,`birth`) VALUES ('$info[1]','$info[2]','$info[3]','$info[4]','$info[5]','$info[6]','$info[7]','$info[8]','$info[9]','$info[10]')";
try{
$insert_result=mysqli_query($conn, $insert_query);
if($insert_result)
{
if(mysqli_affected_rows($conn)>0){
echo("data inserted successfully");
}else{
echo("data are not inserted");
}
}
}catch(Exception $ex){
echo("error inserted".$ex->getMessage());
}
}
//delete
if(isset($_POST['delete'])){
$info = getData();
$delete_query = "DELETE FROM `smash` WHERE id = '$info[0]'";
try{
$delete_result = mysqli_query($conn, $delete_query);
if($delete_result){
if(mysqli_affected_rows($conn)>0)
{
echo("data deleted");
}else{
echo("data not deleted");
}
}
}catch(Exception $ex){
echo("error in delete".$ex->getMessage());
}
}
//edit
if(isset($_POST['update'])){
$info = getData();
$update_query="UPDATE `smash` SET `name`='$info[1]',fname='$info[2]',email='$info[3]',phone='$info[4]',state='$info[5]',qualification='$info[6]',branch='$info[7]',rollno='$info[8]',rollno='$info[9]',birth='$info[10]' WHERE id = '$info[0]'";
try{
$update_result=mysqli_query($conn, $update_query);
if($update_result){
if(mysqli_affected_rows($conn)>0){
echo("data updated");
}else{
echo("data not updated");
}
}
}catch(Exception $ex){
echo("error in update".$ex->getMessage());
}
}
?>
<body>
<div class="container-fliud">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#nav">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="http://localhost/management/">Management System</a>
</div>
<div class="collapse navbar-collapse" id="nav">
<ul class="nav navbar-nav">
<li class="active"><a href="http://localhost/management">Home</a></li>
<li><a href="http://localhost/management/studentform.php">Enter Student Data </a></li>
<li><a href="http://localhost/management/teacher.php">Enter Teacher Data </a></li>
<li><a href="http://localhost/management/updatestudentdata.php">Update Student Data </a></li>
<li><a href="http://localhost/management/updateteacherdata.php">Update Teacher Data </a></li>
</ul>
</div>
</div>
</nav>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-lg-4">
<form method ="post" action="">
<h1>ID Number (Use to Search Student data)</h1>
<input type="number" name="id" class="form-control" placeholder="ID No. /Automatic Number Genrates" value="<?php echo($id);?>" disabled>
<div class="form-group row">
<div class="col-xs-6">
<h1>Student Name</h1>
<input type="text" name="name" class="form-control" placeholder="Enter Student Name" value="<?php echo($name);?>" required>
</div>
<div class="col-xs-6">
<h1>Father Name</h1>
<input type="text" name="fname" class="form-control" placeholder="Enter Father Name" value="<?php echo($fname);?>" required>
</div>
</div>
<h1>Email</h1>
<input type="email" name="email" class="form-control" placeholder="Enter Email" value="<?php echo($email);?>" required>
<h1>Phone (10-digit)</h1>
<input type="tel" pattern="^\d{10}$" class="form-control" name="phone" placeholder="10 digit Phone number" value="<?php echo($phone);?>">
<div class="form-group row">
<div class="col-xs-6">
<h1>Select State</h1>
<select name="state" class="form-control" value="<?php echo($state);?>">
<option value="JAMMU and KASHMIR">JAMMU and KASHMIR</option>
<option value="HIMACHAL PRADESH">HIMACHAL PRADESH</option>
<option value="PUNJAB">PUNJAB</option>
<option value="UTTARAKHAND">UTTARAKHAND</option>
<option value="HARYANA">HARYANA</option>
<option value="UTTAR PRADESH">UTTAR PRADESH</option>
<option value="RAJASTHAN">RAJASTHAN</option>
<option value="GUJRAT">GUJRAT</option>
<option value="MADHYA PRADESH">MADHYA PRADESH</option>
<option value="BIHAR">BIHAR</option>
<option value="JHARKHAND">JHARKHAND</option>
<option value="GANGTOK">GANGTOK</option>
<option value="KOLKATA">KOLKATA</option>
<option value="ARUNACHAL PRADESH">ARUNACHAL PRADESH</option>
<option value="ASSAM">ASSAM</option>
<option value="MEGHALAYA">MEGHALAYA</option>
<option value="NAGALAND">NAGALAND</option>
<option value="MANIPUR">MANIPUR</option>
<option value="MIZORAM">MIZORAM</option>
<option value="AIZAWL">AIZAWL</option>
<option value="AGARTALA">AGARTALA</option>
<option value="CHHATTISGARH">CHHATTISGARH</option>
<option value="MAHARASHTRA">MAHARASHTRA</option>
<option value="ODISHA">ODISHA</option>
<option value="GOA">GOA</option>
<option value="KARNATAKA">KARNATAKA</option>
<option value="ANDHARA PRADESH">ANDHARA PRADESH</option>
<option value="KERALA">KERALA</option>
<option value="TAMIL NADU"></option>
</select>
</div>
<div class="col-xs-6">
<h1>Qualification</h1>
<select name="qualification" class="form-control" value="<?php echo($qualification);?>">
<option value="10th with above 75%">10th with above 75%</option>
<option value="+2 with above 75%">+2 with above 75%</option>
<option value="10th %age between 50% to 75%">10th %age between 50% to 75%</option>
<option value="+2 %age between 50% to 75%">+2 %age between 50% to 75%</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-xs-6">
<h1>Branch and Semester</h1>
<select name="branch" class="form-control" value="<?php echo($branch);?>">
<option value="Branch CSE 1st sem">Branch CSE 1st sem</option>
<option value="Branch CSE 2nd sem">Branch CSE 2nd sem</option>
<option value="Branch CSE 3rd sem">Branch CSE 3rd sem</option>
<option value="Branch CSE 4th sem">Branch CSE 4th sem</option>
<option value="Branch CSE 5th sem">Branch CSE 5th sem</option>
<option value="Branch CSE 6th sem">Branch CSE 6th sem</option>
</select>
</div>
<div class="col-xs-6">
<h1>Roll No</h1>
<input type="number" class="form-control" name="rollno" placeholder="Enter the Roll no" max="1000" value="<?php echo($rollno);?>" required>
</div>
</div>
<div class="form-group row">
<div class="col-xs-6">
<h1>Gender</h1>
<select name="gender" class="form-control" value="<?php echo($gender);?>">
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<div class="col-xs-6">
<h1>Select Birth Year</h1>
<select name="birth" class="form-control">
<option value="1999">Year</option>
<option>1999</option>
<option>1998</option>
<option>1997</option>
<option>1996</option>
<option>1995</option>
<option>1994</option>
<option>1993</option>
<option>1992</option>
<option>1991</option>
<option>1990</option>
</select>
</div>
</div>
<div>
<input type="submit" class="btn btn-success btn-block btn-lg" name="insert" value="Add">
<a href="http://localhost/management/updatestudentdata.php"<button class="btn btn-info btn-block btn-lg">Update | Delete | Find</button></a>
</div>
</form>
</div>
<div class="col-lg-8">
<h2>Student Data</h2>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "hack";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id,name,fname,email,phone,state,qualification,branch,rollno,gender,birth FROM smash";
$result = $conn->query($sql);
echo "<table border='1'>
<tr>
<th>Search ID</th>
<th>Name</th>
<th>Father Name</th>
<th>Email</th>
<th>Phone</th>
<th>State</th>
<th>Qualification</th>
<th>branch</th>
<th>roll no</th>
<th>gender</th>
<th>birth</th>
</tr>";
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['fname'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['phone'] . "</td>";
echo "<td>" . $row['state'] . "</td>";
echo "<td>" . $row['qualification'] . "</td>";
echo "<td>" . $row['branch'] . "</td>";
echo "<td>" . $row['rollno'] . "</td>";
echo "<td>" . $row['gender'] . "</td>";
echo "<td>" . $row['birth'] . "</td>";
echo "</tr>";
}
} else {
echo "0 results";
}
$conn->close();
?>
</div>
</div>
</body>
</html>