-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
93 lines (69 loc) · 2.67 KB
/
signup.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
<?php
require_once 'admin/config.php';
require_once 'admin/connection.php';
$dbConn = connect();
if (!empty($_POST['submit'])) {
if (!empty($_POST['username'])) {
$username = $_POST['username'];}
if (!empty($_POST['password'])) {
$password = $_POST['password'];
}
if (!empty($_POST['re-password'])) {
$rePassword = $_POST['re-password'];
}
if (!empty($_POST['email'])) {
$email = $_POST['email'];
}
if (empty($username)) {
$error['username'] = 'Please enter the username';
}
if (empty($password)) {
$error['password'] = 'Please enter the password';
}
if (empty($email)) {
$error['email'] = 'Please enter the email';
}
if ($_POST['password'] !== $_POST['re-password']) {
$error['re-password'] = 'Passwords do not match';
}
if ( empty($error) ) {
$query = 'INSERT INTO `users` (username,password,email) VALUES (\'' . $username . '\',\'' . md5($password) . '\',\'' . $email . '\')';
$result = mysql_query($query, $dbConn);
header( 'Location: index.php?register=true' );
die;
}
}
?>
<?php
include_once 'header.php';
?>
<h1>Register</h1>
<?php if (!empty($error)) : ?>
<ul>
<?php foreach ($error as $message) : ?>
<li><?php echo $message; ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<form action="signup.php" method="post">
<div class="form-group">
<label for="user">Username</label>
<input type="text" class="form-control" id="username" name="username" placeholder="Username" value="<?php echo (!empty($username) ? $username : ''); ?>">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password" value="<?php echo (!empty($password) ? $password : ''); ?>">
</div>
<div class="form-group">
<label for="re-password">Repeat Password</label>
<input type="password" class="form-control" id="re-password" name="re-password" placeholder="Repeat password" value="<?php echo (!empty($rePassword) ? $rePassword : ''); ?>">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="text" class="form-control" id="email" name="email" placeholder="Email" value="<?php echo (!empty($email) ? $email : ''); ?>">
</div>
<div class="form-group">
<input name="submit" type="submit" value="Sign up" class="btn btn-primary" />
</div>
</form>
<?php include_once 'footer.php'; ?>