-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration.php
119 lines (78 loc) · 3.41 KB
/
registration.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
<?php include "includes/header.php"; ?>
<!-- Navigation -->
<?php include "includes/navigation.php"; ?>
<?php
if (isset($_POST['submit'])) {
$username =trim($_POST['username']);
$password =trim($_POST['password']);
$email =trim($_POST['email']);
$error = [
'username'=> '',
'password'=>'',
'email'=>'' ,
];
if(strlen($username) < 4){
$error['username'] = 'username to short';
}
if(empty($username)){
$error['username'] = 'username cannot be empty';
}
if(strlen($password) < 4){
$error['password'] = 'password to short';
}
if(empty($password)){
$error['password'] = 'password cannot be empty';
}
if(usernameExists($username)){
$error['username'] = 'username already taken , please <a href="index.php">please login</a>';
}
if(empty($email)){
$error['email'] = 'email cannot be empty';
}
if(emailExists($username)){
$error['email'] = 'email already taken , please <a href="index.php">please login</a>';
}
foreach ($error as $key => $value) {
if(empty($value)){
unset($error[$key]);
}
if(empty($error)){
registerUser($username , $email, $password);
loginUser($username, $password);
}
}
}
?>
<!-- Page Content -->
<div class="container">
<section id="login">
<div class="container">
<div class="row">
<div class="col-xs-6 col-xs-offset-3">
<div class="form-wrap">
<h1>Register</h1>
<form role="form" action="registration.php" method="post" id="login-form" autocomplete="on">
<div class="form-group">
<label for="username" class="sr-only">username</label>
<input type="text" name="username" id="username" class="form-control" placeholder="Enter Desired Username" autocomplete="on" value="<?php echo isset($username)? $username: '' ?>">
<p><?php echo isset($error['username'])? $error['username']: '' ?></p>
</div>
<div class="form-group">
<label for="email" class="sr-only">Email</label>
<input type="email" name="email" id="email" class="form-control" placeholder="[email protected]" value="<?php echo isset($email)? $email: '' ?>">
<p><?php echo isset($error['email'])? $error['email']: '' ?></p>
</div>
<div class="form-group">
<label for="password" class="sr-only">Password</label>
<input type="password" name="password" id="key" class="form-control" placeholder="Password">
<p><?php echo isset($error['password'])? $error['password']: '' ?></p>
</div>
<input type="submit" name="submit" id="btn-login" class="btn btn-custom btn-lg btn-block" value="Register">
</form>
</div>
</div> <!-- /.col-xs-12 -->
</div> <!-- /.row -->
</div> <!-- /.container -->
</section>
<hr>
<?php include "includes/footer.php"; ?>