-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.php
89 lines (69 loc) · 2.41 KB
/
register.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
<HTML>
<HEAD>
<body background="bg.jpg">
<?php
require( "config.php" );
session_start();
if(isset($_POST["register"]))
{
register1();
}
function register1() {
$results = array();
$results['pageTitle'] = "User Registration";
$sql = "INSERT INTO users (name,password,rolecode) VALUES(:name,:password,:user)";
$sql2 = "SELECT * from users WHERE name = :name";
try
{
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare( $sql2 );
$stmt->bindValue( ":name", $_POST["username"], PDO::PARAM_STR );
$stmt->execute();
$rows = $stmt->fetchAll();
if (count($rows) > 0)
{
//username already present
$results['errorMessage'] = "Username Already Present.";
require( TEMPLATE_PATH . "/admin/loginForm.php" );
}
else
{
// unique username
$stmt = $conn->prepare( $sql );
$stmt->bindValue( ":name", $_POST["username"], PDO::PARAM_STR );
$stmt->bindValue( ":password", password_hash($_POST["password"], PASSWORD_BCRYPT), PDO::PARAM_STR );
$stmt->bindValue( ":user", "user", PDO::PARAM_STR );
$stmt->execute();
header( "Location: login.php" );
}
}
catch(Exception $e)
{
echo "Error".$e;
}
}
?>
<?php include "templates/include/header.php" ?>
<form action="register.php?action=register" method="post" style="width: 50%;">
<input type="hidden" name="register" value="true" />
<?php if ( isset( $results['errorMessage'] ) ) { ?>
<div class="errorMessage"><?php echo $results['errorMessage'] ?></div>
<?php } ?>
<ul>
<li>
<label for="username">Username</label>
<input type="text" name="username" id="username" placeholder="Your user name" required autofocus maxlength="20" />
</li>
<li>
<label for="password">Password</label>
<input type="password" name="password" id="password" placeholder="Your user password" required maxlength="20" />
</li>
</ul>
<div class="buttons">
<input type="submit" name="regist" value="SignUp" />
</div>
</form>
<?php include "templates/include/footer.php" ?>
</body>
</html>