-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
169 lines (103 loc) · 3.64 KB
/
server.php
File metadata and controls
169 lines (103 loc) · 3.64 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php
session_start();
//intialing variables
$firstname ="";
$lastname ="";
$regno ="";
$npassword ="";
$cpassword ="";
$email ="";
$ans ="";
$sname ="";
$pname="";
$smob ="";
$pmob="";
$dob="";
$dept="";
$comp="";
$resultss="";
$regnum="";
$errors = array();
//connect to sdb
$db= mysqli_connect('localhost','root','','final') or die("could not connect to db");
//registration comes here;
if(isset($_POST['submit'])){
$firstname = mysqli_real_escape_string($db,$_POST['firstname']);
$lastname = mysqli_real_escape_string($db, $_POST['lastname']);
$regno = mysqli_real_escape_string($db, $_POST['regno']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$npassword = mysqli_real_escape_string($db, $_POST['npassword']);
$cpassword= mysqli_real_escape_string($db, $_POST['cpassword']);
$ans= mysqli_real_escape_string($db, $_POST['ans']);
if(empty($firstname)){array_push($errors,"firstname is required");}
if(empty($lastname)){array_push($errors,"lastname is required");}
if(empty($regno)){array_push($errors,"regno is required");}
if(empty($email)){array_push($errors,"email is required");}
if(empty($npassword)){array_push($errors,"npassword is required");}
if($npassword != $cpassword){array_push($errors,"cpassword is not matched");}
if(empty($ans)){array_push($errors,"ans is required");}
//cheaking for user
$user_check="SELECT * FROM `test1` WHERE regno= '$regno' LIMIT 1";
$result =mysqli_query($db,$user_check);
$user = mysqli_fetch_assoc($result);
if($user){
if($user['regno'] ===$regno){
array_push($errors,"User Already Exits Please Login");
}
}
//registering user
if(count($errors) == 0){
echo '$regno';
$password =md5($npassword);
echo $regno;
echo $password;
$query ="INSERT INTO `test1`(`firstname`, `lastname`, `regno`, `email`, `password`,`ans`) VALUES ('$firstname','$lastname','$regno','$email','$password','$ans')";
mysqli_query($db,$query);
$_SESSION['regno'] = $regno;
$_SESSION['success']= "you are registered in";
header('location:login basic.php');
}
}
//student login
if(isset($_POST['login'])){
$regno = mysqli_real_escape_string($db, $_POST['regno']);
$npassword = mysqli_real_escape_string($db, $_POST['lpassword']);
if(empty($regno)){array_push($errors,"regno is required");}
if(empty($npassword)){array_push($errors,"password is required");}
if(count($errors) == 0)
{
$ppassword =md5($npassword);
$query = "SELECT * FROM `test1` WHERE regno='$regno' AND password='$ppassword'";
$results=mysqli_query($db,$query);
if($results&&mysqli_num_rows($results)>0)
{$_SESSION['regno'] = $regno;
$_SESSION['success'] ="loged in succes";
header('location:index.php');
}
else{
array_push($errors,"not matching creadites");
}
}
}
//complainting
if (isset($_POST['give'])) {
$regnum = mysqli_real_escape_string($db,$_SESSION['regno']);
$comp = mysqli_real_escape_string($db, $_POST['complaint']);
if(empty($regnum)){array_push($errors,"regnum is required");}
if(empty($comp)){array_push($errors,"complaint is required");}
if(count($errors) == 0){
$que = "INSERT INTO `complaint`(`regno`,`complaint`) VALUES ('$regnum','$comp')";
$resultss=mysqli_query($db,$que);
echo $resultss;
if ($resultss) {
echo "<h4>successfully submited complaint</h4>";
}
}
}
//logging out student
if (isset($_POST['logout'])) {
session_destroy();
unset($_SESSION['regno']);
header("location:login basic.php");
}
?>