-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
161 lines (151 loc) · 5.63 KB
/
signup.php
File metadata and controls
161 lines (151 loc) · 5.63 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
<!DOCTYPE html>
<?php require_once("config.php"); ?>
<html>
<head>
<title> SignUp </title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
<style>
.form-group {
margin-bottom: -4rem;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-4">
</div>
<div class="col-sm-4">
</div>
<div class="col-sm-4">
</div>
</div>
<div class="row">
<?php
if(isset($_POST['signup'])){
extract($_POST);
if(strlen($fname)<3){ // Minimum
$error[] = 'Please enter First Name using 3 charaters atleast.';
}
if(strlen($fname)>20){ // Max
$error[] = 'First Name: Max length 20 Characters Not allowed';
}
if(!preg_match("/^[A-Za-z _]*[A-Za-z ]+[A-Za-z _]*$/", $fname)){
$error[] = 'Invalid Entry First Name. Please Enter letters without any Digit or special symbols like ( 1,2,3#,$,%,&,*,!,~,`,^,-,)';
}
if(strlen($lname)<3){ // Minimum
$error[] = 'Please enter Last Name using 3 charaters atleast.';
}
if(strlen($lname)>20){ // Max
$error[] = 'Last Name: Max length 20 Characters Not allowed';
}
if(!preg_match("/^[A-Za-z _]*[A-Za-z ]+[A-Za-z _]*$/", $lname)){
$error[] = 'Invalid Entry Last Name. Please Enter letters without any Digit or special symbols like ( 1,2,3#,$,%,&,*,!,~,`,^,-,)';
}
if(strlen($username)<3){ // Change Minimum Lenghth
$error[] = 'Please enter Username using 3 charaters atleast.';
}
if(strlen($username)>50){ // Change Max Length
$error[] = 'Username : Max length 50 Characters Not allowed';
}
if(!preg_match("/^^[^0-9][a-z0-9]+([_-]?[a-z0-9])*$/", $username)){
$error[] = 'Invalid Entry for Username. Enter lowercase letters without any space and No number at the start- Eg - myusername, okuniqueuser or myusername123';
}
if(strlen($email)>50){ // Max
$error[] = 'Email: Max length 50 Characters Not allowed';
}
if($passwordConfirm ==''){
$error[] = 'Please confirm the password.';
}
if($password != $passwordConfirm){
$error[] = 'Passwords do not match.';
}
if(strlen($password)<5){ // min
$error[] = 'The password is 6 characters long.';
}
if(strlen($password)>20){ // Max
$error[] = 'Password: Max length 20 Characters Not allowed';
}
$sql="select * from users where (username='$username' or email='$email');";
$res=mysqli_query($dbc,$sql);
if (mysqli_num_rows($res) > 0) {
$row = mysqli_fetch_assoc($res);
if($username==$row['username'])
{
$error[] ='Username alredy Exists.';
}
if($email==$row['email'])
{
$error[] ='Email alredy Exists.';
}
}
if(!isset($error)){
$date=date('Y-m-d');
$options = array("cost"=>4);
$password = password_hash($password,PASSWORD_BCRYPT,$options);
$result = mysqli_query($dbc,"INSERT into users values('$fname','$lname','$username','$email','$password','$date')");
if($result)
{
$done=2;
}
else{
$error[] ='Failed : Something went wrong';
}
}
} ?>
<div class="col-sm-4">
<?php
if(isset($error)){
foreach($error as $error){
echo '<p class="errmsg">⚠'.$error.' </p>';
}
}
?>
</div>
<div class="col-sm-4">
<?php if(isset($done))
{ ?>
<div class="successmsg"><span style="font-size:100px;">✅</span> <br> You have registered successfully . <br> <a href="login.php" style="color:#fff;">Login here... </a> </div>
<?php } else { ?>
<div class="signup_form">
<form action="" method="POST">
<div class="form-group">
<label class="label_txt">First Name</label>
<input type="text" class="form-control" name="fname" value="<?php if(isset($error)){ echo $_POST['fname'];}?>" required="">
</div>
<div class="form-group">
<label class="label_txt">Last Name </label>
<input type="text" class="form-control" name="lname" value="<?php if(isset($error)){ echo $_POST['lname'];}?>" required="">
</div>
<div class="form-group">
<label class="label_txt">Username </label>
<input type="text" class="form-control" name="username" value="<?php if(isset($error)){ echo $_POST['username'];}?>" required="">
</div>
<div class="form-group">
<label class="label_txt">Email </label>
<input type="email" class="form-control" name="email" value="<?php if(isset($error)){ echo $_POST['email'];}?>" required="">
</div>
<div class="form-group">
<label class="label_txt">Password </label>
<input type="password" name="password" class="form-control" required="">
</div>
<div class="form-group">
<label class="label_txt">Confirm Password </label>
<input type="password" name="passwordConfirm" class="form-control" required="">
</div>
<button type="submit" name="signup" class="btn btn-primary btn-group-lg form_btn signupbtn">SignUp</button>
<p>Have an account? <a href="login.php">Log in</a> </p>
</form>
<?php } ?>
</div>
</div>
<div class="col-sm-4">
</div>
</div>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.bundle.min.js"></script>
</html>