-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadduser.php
More file actions
142 lines (129 loc) · 5.44 KB
/
adduser.php
File metadata and controls
142 lines (129 loc) · 5.44 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
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
<?php
session_start();
require('connect.php');
if($_SERVER["REQUEST_METHOD"] == "POST")
{
if($_POST && !empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['passwordConfirm']) && !empty($_POST['email']))
{
// Filter, Saniitize and set variables.
$hasErrors = false;
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
$password = filter_input(INPUT_POST, 'password', FILTER_SANITIZE_SPECIAL_CHARS);
$passwordConfirm = filter_input(INPUT_POST, 'passwordConfirm', FILTER_SANITIZE_SPECIAL_CHARS);
$email = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
if(!filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL))
{
$hasErrors = true;
$emailError = "Email was invalid, please try again.";
}
if($password != $passwordConfirm)
{
$hasErrors = true;
$passwordError = "Passwords did not match. Please try again.";
}
// If passwords match, exectue the database insert of the new user.
if(!$hasErrors)
{
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
$insertQuery = "INSERT INTO user (user_name, password, email) VALUES (:username, :password, :email)";
$insertStatement = $db->prepare($insertQuery);
$insertStatement->bindValue(':username', $username);
$insertStatement->bindValue(':password', $hashedPassword);
$insertStatement->bindValue(':email', $email);
$insertStatement->execute();
header('Location: adminpanel.php');
}
else
{
$passwordConfirmationError = "Passwords did not match. Please try again.";
}
}
if(empty($_POST['username']))
{
$userNameError = "Please enter a user name.";
}
if(empty($_POST['password']))
{
$passwordError = "Please enter a password.";
}
if(empty($_POST['passwordConfirm']))
{
$passwordConfirmationError = "Please enter a password matching the previous.";
}
if(empty($_POST['email']))
{
$emailError = "Please enter an E-Mail";
}
}
if(!empty($_POST['search']))
{
$searchTerm = filter_input(INPUT_POST, 'search', FILTER_SANITIZE_SPECIAL_CHARS);
if(!filter_input(INPUT_POST, 'search', FILTER_SANITIZE_SPECIAL_CHARS))
{
header("location: index.php");
}
else
{
$_SESSION['searchterm'] = $searchTerm;
header("location: search.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 href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="style.css">
<title>iMovieRatings | Edit User</title>
</head>
<body>
<?php include 'nav.php'?>
<main>
<section class="bg-dark text-dark p-5 text-left">
<div class="form_bg">
<div class="container">
<form class="form_horizontal" method="post">
<div class="form_icon">
<i class="fa fa-user-circle"></i>
</div>
<h3 class="title">Create Account</h3>
<div class="form-group">
<label class="fs-3" for="Username">Enter New User Name</label>
<input type="text" class="form-control" name="username" type="text" placeholder="username">
<?php if(isset($userNameError)): ?>
<p class="fs-5"><?= $userNameError ?></p>
<?php endif ?>
</div>
<div class="form-group">
<h2>Enter Password:</h2>
<input type="password" class="form-control" name="password" placeholder="password">
<?php if(isset($passwordError)): ?>
<p class="fs-5"><?= $passwordError ?></p>
<?php endif ?>
</div>
<div class="form-group">
<h2>Confirm Password</h2>
<input type="password" class="form-control" name="passwordConfirm" placeholder="confirm password">
<?php if(isset($passwordConfirmationError)): ?>
<p class="fs-5"><?= $passwordConfirmationError ?></p>
<?php endif ?>
</div>
<div class="form-group">
<h2>Enter E-mail:</h2>
<input type="email" class="form-control" name="email" placeholder="email">
<?php if(isset($emailError)): ?>
<p class="fs-5"><?= $emailError ?><p>
<?php endif ?>
</div>
<input class ="btn signin bg-light text-danger" type="submit" name="login" value="Create Account">
</form>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</section>
</main>
</body>