-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregistration.php
166 lines (157 loc) · 5.14 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
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
<?php
session_start();
if (isset($_SESSION["user"])) {
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"/>
<title>Registration Form</title>
<style>
body {
font-family: 'Arial', sans-serif;
background: #000000b3;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background: white;
padding: 20px 25px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
width: 400px;
}
.form-group {
margin-bottom: 15px;
}
.form-group input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
box-sizing: border-box;
}
.form-btn input {
width: 100%;
padding: 10px;
border: none;
border-radius: 5px;
background: blue;
color: white;
font-size: 16px;
cursor: pointer;
}
.form-btn input:hover {
background: #555;
}
.alert {
background-color: #f8d7da;
color: #721c24;
padding: 10px;
margin-bottom: 15px;
border-radius: 5px;
border: 1px solid #f5c6cb;
}
.logo {
margin: auto;
font-size: 8rem;
background: white;
padding: .5em 0.7em;
border-radius: 50% 50%;
color: #000000b3;
z-index: 10;
}
a {
color: #007bff;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
p {
margin: 10px 0;
}
</style>
</head>
<body>
<div class="container">
<?php
if (isset($_POST["submit"])) {
$fullName = $_POST["fullname"];
$email = $_POST["email"];
$password = $_POST["password"];
$passwordRepeat = $_POST["repeat_password"];
$passwordHash = password_hash($password, PASSWORD_DEFAULT);
$errors = array();
if (empty($fullName) OR empty($email) OR empty($password) OR empty($passwordRepeat)) {
array_push($errors,"All fields are required");
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
array_push($errors, "Email is not valid");
}
if (strlen($password)<8) {
array_push($errors,"Password must be at least 8 charactes long");
}
if ($password!==$passwordRepeat) {
array_push($errors,"Password does not match");
}
require_once "database.php";
$sql = "SELECT * FROM users WHERE email = '$email'";
$result = mysqli_query($conn, $sql);
$rowCount = mysqli_num_rows($result);
if ($rowCount>0) {
array_push($errors,"Email already exists!");
}
if (count($errors)>0) {
foreach ($errors as $error) {
echo "<div class='alert alert-danger'>$error</div>";
}
}else{
$sql = "INSERT INTO users (full_name, email, password) VALUES ( ?, ?, ? )";
$stmt = mysqli_stmt_init($conn);
$prepareStmt = mysqli_stmt_prepare($stmt,$sql);
if ($prepareStmt) {
mysqli_stmt_bind_param($stmt,"sss",$fullName, $email, $passwordHash);
mysqli_stmt_execute($stmt);
echo "<div class='alert alert-success'>You are registered successfully.</div>";
}else{
die("Something went wrong");
}
}
}
?>
<form action="registration.php" method="post">
<div class="logo">
<span class="fa fa-hands-helping"></span>
</div>
<div class="form-group">
<input type="text" class="form-control" name="fullname" placeholder="Full Name:">
</div>
<div class="form-group">
<input type="emamil" class="form-control" name="email" placeholder="Email:">
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="Password:">
</div>
<div class="form-group">
<input type="password" class="form-control" name="repeat_password" placeholder="Repeat Password:">
</div>
<div class="form-btn">
<input type="submit" class="btn btn-primary" value="Register" name="submit">
</div>
</form>
<div>
<div><p>Already Registered <a href="login.php">Login Here</a></p></div>
</div>
</div>
</body>
</html>