-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
108 lines (95 loc) · 3.28 KB
/
register.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
<?php
require_once 'core/init.php';
include 'includes/head.php';
include 'includes/navigation.php';
if($_POST) {
$name = @sanitize($_POST['name']);
$email = @sanitize($_POST['email']);
$password = @sanitize($_POST['password']);
$confirmpassword = @sanitize($_POST['confirmpassword']);
$errors = array();
// validade email
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Invalid email';
}
//password is more than 6 characters
if (strlen($password) < 6) {
$errors[] = 'Password must be at least 6 characters long';
}
if($password != $confirmpassword){
$errors[] = 'The new password and the confimation does not confer';
}
//check if email exists in the dtatabase
$query = mysqli_query($db,"SELECT * FROM users WHERE email='$email'");
$user = mysqli_fetch_assoc($query);
$userCount = mysqli_num_rows($query);
if($userCount > 0){
$errors[] = 'This email already exists in our database';
}
$required = array('name', 'email', 'password', 'confirmpassword');
foreach($required as $field) {
if($_POST[$field] == '') {
$errors[] = 'All fields with an anterisk are required!';
break;
}
}
if(!empty($errors)) {
$error=display_errors($errors);
} else {
$hashed= password_hash($password,PASSWORD_DEFAULT);
$insertSql = "INSERT INTO users (full_name, email, password, confirmed) VALUES ('$name','$email','$hashed','0')";
mysqli_query($db,$insertSql);
$_SESSION['sucess_flash'] = 'Registration completed!';
echo "<script>window.location.href='login.php'</script>";
}
}
?>
<div class="container-fluid">
<div class="main-content w3-animate-zoom bg-success text-center">
<div class="col-md-4 text-center company__info">
<img src="files/calendar.png" style="max-height:250px;" alt="">
<h4 class="company_title">Online Scheduling tool</h4>
</div>
<div class="col-md-8 col-xs-12 col-sm-12 login_form ">
<div class="w3-container w3-padding-16">
<div class="w3-center">
<h2>Register</h2>
</div>
<div>
<form action="register.php" method="POST" class="form-group">
<div>
<input type="name" name="name" id="name" value="<?php echo @$name;?>" class="form__input" placeholder="Name">
</div>
<div>
<input type="email" name="email" id="email" value="<?php echo @$email;?>" class="form__input" placeholder="Email">
</div>
<div>
<input type="password" name="password" id="password" value="" class="form__input" placeholder="Password">
</div>
<div>
<input type="password" name="confirmpassword" id="confirmpassword" value="" class="form__input" placeholder="Confirm password">
</div>
<div class="w3-padding">
<input type="hidden" name="csrf" value="<?php echo $token1; ?>">
<input type="submit" value="Submit" class="btn1">
</div>
</form>
</div>
<div class="row">
<p>Do you already have an account? <a href="login.php">Login Here</a></p>
<div><?php echo @$error;?></div>
</div>
</div>
</div>
</div>
</div>
<script>
$('form input').keydown(function (e) {
if (e.keyCode == 13) {
e.preventDefault();
return false;
}
});
</script>
<?php
include 'includes/footer.php';?>