-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregistration.php
More file actions
61 lines (55 loc) · 2.61 KB
/
registration.php
File metadata and controls
61 lines (55 loc) · 2.61 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
<?php
require_once "includes/connect.php";
$conn_pdo = PDOPgSQL();
if (isset($_POST['email'])) {
if (strlen($_POST['password']) < 6) {
$error = "Password must be at least 6 characters";
} else {
$_POST['password'] = md5($_POST['password']);
$insertUser = $conn_pdo->prepare("INSERT INTO users (email, password) VALUES (:email, :password)");
$result = $insertUser->execute([
":email" => $_POST['email'],
":password" => $_POST['password']
]);
$selectUser = $conn_pdo->prepare("SELECT `id` FROM users WHERE email = :email AND password = :password");
$result1 = $selectUser->execute([
":email" => $_POST['email'],
":password" => $_POST['password']
]);
$rows = $selectUser->fetchAll(PDO::FETCH_ASSOC);
if ($result === false){
$error = "Email already exists";
} else {
$_SESSION['email'] = $_POST['email'];
$_SESSION['user_id'] = $rows[0]['id'];
$_SESSION['role'] = $rows[0]['role'];
$success = "You have successfully registered! <a href='/'>You can go to the main page</a>";
}
}
}
?>
<?php include_once "includes/header.php" ?>
<?php include_once "includes/menu.php" ?>
<div class="d-flex justify-content-center">
<div class="col-lg-4" style="margin-top: 100px; ">
<h2>Registration Form</h2>
<?php if (isset($error)) { echo "<div class='alert alert-danger'><strong>Error! </strong> $error</div>"; } ?>
<?php if (isset($success)) { echo "<div class='alert alert-success'><strong>Great! </strong> $success</div>"; } ?>
<form class="form-check" action="" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Email address</label>
<input type="email" name="email" value="<?= $_POST['email'] ?>" required class="form-control" id="exampleInputEmail1"
aria-describedby="emailHelp" placeholder="something@gmail.com">
<!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>-->
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" name="password" required class="form-control" id="exampleInputPassword1"
placeholder="your password">
</div>
<button type="submit" class="btn btn-primary">Enter</button>
</form>
<p style=" margin-top: 10px; font-size: 14px;">You have already registered? <a href="login.php">Login.</a></p>
</div>
</div>
<?php include_once "includes/footer.php" ?>