-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent_signup.php
190 lines (156 loc) · 4.91 KB
/
student_signup.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
<?php
session_start();
require 'config/db_connect.php';
$errors=array('id_card'=>'','fname'=>'','lname'=>'','password'=>'','cpassword'=>'','email'=>'','phone'=>'','dob'=>'');
if(isset($_POST['signup']))
{
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$dob=$_POST['DOB'];
$email=$_POST["email"];
$phone=$_POST["phone"];
$password=$_POST['password'];
$cpassword=$_POST['cpassword'];
$valid=true;
//Validate first name
if(strlen($fname)==0)
{
$errors['fname']="*First Name can't be empty";
$valid=false;
}
else
{
for($i=0;$i<strlen($fname);$i++)
{
if(!ctype_alpha($fname[$i]))
{
$errors['fname']='*First Name can contain only alphabets';
$valid=false;
break;
}
}
}
//Validate last name
if(strlen($lname)==0)
{
$errors['lname']="*Last Name can't be empty";
$valid=false;
}
else
{
for($i=0;$i<strlen($lname);$i++)
{
if(!ctype_alpha($lname[$i]))
{
$errors['lname']='*Last Name can contain only alphabets';
$valid=false;
break;
}
}
}
$temp_file_name=addslashes($_FILES['id_card']['tmp_name']);
$file_name=addslashes($_FILES['id_card']['name']);
$image=file_get_contents($temp_file_name);
$image=base64_encode($image);
//Validate Email
$sql1="SELECT * FROM students WHERE email='$email'";
$sql2="SELECT * FROM managers WHERE email='$email'";
if(mysqli_num_rows(mysqli_query($conn,$sql1))>0|| mysqli_num_rows(mysqli_query($conn,$sql2))>0){
$errors['email']='*An account with this email id already exists';
$valid=false;
}
//Validate phone
if(strlen($phone)==0)
{
$errors['phone']="*Phone number can't be empty";
$valid=false;
}
else if(strlen($phone)!=10)
{
$errors['phone']="*Invalid phone number";
$valid=false;
}
else
{
for($i=0;$i<strlen($phone);$i++)
{
if(!ctype_digit($phone[$i]))
{
$errors['phone']="*Invalid phone number";
$valid=false;
break;
}
}
}
//Validate password/confirm password
if(strlen($password)==0)
{
$errors['password']="*Password can't be empty";
$valid=false;
}
else
{
if($password!=$cpassword)
{
$errors['cpassword']='*Passwords do not match';
$valid=false;
}
}
//If everything is valid
if($valid)
{
if($conn)
{
$sql="INSERT INTO students
(first_name,last_name,date_of_birth,mobile,email,password,id_card)
VALUES
('$fname','$lname','$dob','$phone','$email','$password','$image')";
if(mysqli_query($conn,$sql))
{
$_SESSION['username'] = $email;
$_SESSION['status']='Not Hostelite And Not Yet Applied';
setcookie("user_email",$email,time()+60*60*24,'/');
header("location: Students/profile.php");
}
}
mysqli_close($conn);
}
}
?>
<!DOCTYPE html>
<html>
<?php include('templates/header.php'); ?>
<section class="container grey-text">
<h4 class="center heading-text">Student SignUp Page</h4>
<form class="white" action="student_signup.php" method="post" enctype="multipart/form-data">
<label><h5>First Name: </h5></label>
<input type="text" name="fname" value="<?php echo isset($_POST["fname"]) ? $_POST["fname"] : ''; ?>">
<div class="red-text"><?php echo $errors['fname']; ?></div>
<label><h5>Last Name: </h5></label>
<input type="text" name="lname" value="<?php echo isset($_POST["lname"]) ? $_POST["lname"] : ''; ?>">
<div class="red-text"><?php echo $errors['lname']; ?></div>
<label><h5>ID Card: </h5></label>
<input type="file" name="id_card" required>
<div class="red-text"><?php echo $errors['id_card']; ?></div><br>
<label><h5>Date of Birth: </h5></label>
<input type="date" name="DOB" value="<?php echo isset($_POST["DOB"]) ? $_POST["DOB"] : ''; ?>">
<div class="red-text"><?php echo $errors['dob']; ?></div>
<label><h5>Email: </h5></label>
<input type="email" name="email" value="<?php echo isset($_POST["email"]) ? $_POST["email"]: ''; ?>">
<div class="red-text"><?php echo $errors['email']; ?></div>
<label><h5>Phone: </h5></label>
<input type="text" name="phone" value="<?php echo isset($_POST["phone"]) ? $_POST["phone"]: '';?>">
<div class="red-text"><?php echo $errors['phone']; ?></div>
<label><h5>Password: </h5></label>
<input type="password" name="password" value="<?php echo isset($_POST["password"]) ? $_POST["password"] : ''; ?>">
<div class="red-text"><?php echo $errors['password']; ?></div>
<label><h5>Confirm Password: </h5></label>
<input type="password" name="cpassword" value="<?php echo isset($_POST["cpassword"]) ? $_POST["cpassword"] : ''; ?>">
<div class="red-text"><?php echo $errors['cpassword']; ?></div>
<div class="center">
<input type="submit" name="signup" value="Create" class="btn brand z-depth-0">
</div>
</form>
</section>
<?php include('templates/footer.php'); ?>
</html>