-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregistration.php
78 lines (68 loc) · 2.13 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
<?php
include 'includes/header.php';
$errors = [];
if(isset($_POST['submit'])) {
$name = trim($_POST['name']);
$email = trim($_POST['email']);
$password = $_POST['password'];
$nameLength = mb_strlen($name);
if($nameLength < 1 || $nameLength > 30) {
$errors['name'] = 'Name is not correct';
}
if(filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
$errors['email'] = 'Email is not correct';
}
$existEmailQuery = $db->prepare("SELECT * FROM users WHERE email = :email");
$existEmailQuery->execute([
'email' => $email,
]);
if($existEmailQuery->fetch() !== false) {
$errors['email'] = 'EMail is exist';
}
$passwordLength = mb_strlen($password);
if($passwordLength < 3) {
$errors['password'] = 'Password is not correct';
}
if(count($errors) === 0) {
$insertQuery = $db->prepare("INSERT INTO users (name, email, password) VALUES (:name, :email, :password)");
$insertQuery->execute([
'name' => $name,
'email' => $email,
'password' => md5($password),
]);
redirect('login.php');
}
}
?>
<h1>Registration</h1>
<form action="registration.php" novalidate method="post">
<div>
<label>
Name:
<input type="text" placeholder="Your name" name="name"
value="<?= $name ?? '' ?>"
>
<?= $errors['name'] ?? '' ?>
</label>
</div>
<div>
<label>
E-Mail:
<input type="email" placeholder="Your email" name="email"
value="<?= $email ?? '' ?>">
<?= $errors['email'] ?? '' ?>
</label>
</div>
<div>
<label>
Password:
<input type="password" placeholder="Your password" name="password">
<?= $errors['password'] ?? '' ?>
</label>
</div>
<div>
<input type="submit" name="submit" value="Registration">
</div>
</form>
<?php
include 'includes/footer.php';