-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewStudent.php
More file actions
138 lines (113 loc) · 2.69 KB
/
viewStudent.php
File metadata and controls
138 lines (113 loc) · 2.69 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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo_form";
$con="";
$Name="";
$Roll = "";
$Dept = "";
$Email = "";
$Address = "";
$About = "";
$details = "";
$roll_error = "";
$result="";
$row="";
if(isset($_GET["submit"])){
// Create connection
$con = mysqli_connect($servername, $username, $password);
// Check connection
if (!$con) {
$message = "Not connected to server";
}
//echo "Connected successfully";
if(!mysqli_select_db($con,$dbname))
{
$message = "Database not selected";
}
//Create a function to validate the input data
function test_input($link,$data){
$data = trim($data);
$data = stripslashes($data);
$data = strip_tags($data);
$data = htmlspecialchars($data);
$data = mysqli_real_escape_string($link,$data);
return $data;
}
if(empty($_GET["roll"])){
$roll_error = "*Roll number is required.";
}
else{
$Roll = test_input($con,$_GET['roll']);
if(strlen($Roll)==9){
if(preg_match("/^[1-9][0-9]{0,8}$/",$Roll)){
$roll_error = "";
}
else{
$roll_error = "Invalid Roll number";
}
}
else{
$roll_error = "Roll number should contain 9 digits";
}
}
if(empty($roll_error)){
$sql = "SELECT * FROM student WHERE Roll_Number = ".$Roll;
if($result = mysqli_query($con,$sql)){
while($row = mysqli_fetch_row($result)){
$Name = $row[0];
$Roll = $row[1];
$Dept = $row[2];
$Email = $row[3];
$Address = $row[4];
$About = $row[5];
}
if(empty($Name)){
$details = "Sorry! No match found";
}
else{
$details = " Name : ".$Name."\n Roll number : ".$Roll."\n Department : ".$Dept."\n Email : ".$Email
."\n Address : ".$Address."\n About : ".$About;
}
mysqli_free_result($result);
}
else
{
$details = "Sorry! No data found!";
}
}
}
?>
<html>
<head>
<title>VIEW STUDENT DATABASE</title>
<style>
.error{
color:#FF0000;
}
</style>
</head>
<?php
?>
<body>
<form method="get" name="viewForm" action=" <?php echo ($_SERVER['PHP_SELF']);?> ">
<p>Roll Number* : <input type="text" name="roll" value="<?php echo $Roll;?>" >
<span class = "error"><?php echo $roll_error;?></span>
</p>
<input type="submit" name = "submit" value="Submit" onclick="clickEvent()" />
</form>
<button onclick="sendData()">EDIT</button>
<form name="editForm" method="get" action="http://localhost/confirmStudent.php?edit_roll_no="<?php echo $Roll;?>>
<input type = "hidden" name = "edit_roll_no"></input>
</form>
<script>
function sendData(){
document.editForm.edit_roll_no.value = document.viewForm.roll.value;
document.editForm.submit();
}
</script>
<br>
<?php echo nl2br($details) ?>
</body>
</html>