-
Notifications
You must be signed in to change notification settings - Fork 5
/
signup.php
69 lines (65 loc) · 2.37 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
<?php
require_once 'inc/func.inc.php';
require_once 'inc/connection.inc.php';
$error_message = array(
"Entered Passwords do not match",
"Username cannot have white spaces",
"Username Already Taken",
"Successfully Register. Now Please Login To Proceed", //success case
);
if(loggedin())
header('Location: index.php');
if(isset($_POST['submit'])){
$name = strtolower(strip_tags($_POST['name']));
$username = strip_tags($_POST['username']);
$pass = md5(strip_tags($_POST['pass']));
$conf_pass = md5(strip_tags($_POST['confpass']));
if($conf_pass != $pass){
$error = 0;
} elseif(preg_match('/\s/',$username)){
$error = 1;
} else {
$query = "SELECT `id` FROM `users` WHERE `username`='$username'";
if(mysqli_num_rows(mysqli_query($connection, $query)) > 0 ){
$error = 2;
} else {
$query = "INSERT INTO `users` (`username`,`password`,`name`) VALUES ('$username','$pass','$name')";
mysqli_query($connection, $query);
$error = 3;
header('Location: login.php?signup=true');
}
}
}
?>
<div class="container">
<?php
if(isset($error)){
echo $error_message[$error];
echo '<br>';
}
?>
<div class="row">
<div class="col-md-6 col-lg-6">
<form id="login-form" method="POST">
<h1>sign up</h1>
<div class="form-group">
<label>Name *</label>
<input name="name" type="text" class="form-control" placeholder="Enter Your Name" required>
</div>
<div class="form-group">
<label>Username *</label>
<input name="username" type="text" class="form-control" placeholder="Enter Username" required>
</div>
<div class="form-group">
<label>Password *</label>
<input name="pass" type="password" class="form-control" placeholder="Password" required>
</div>
<div class="form-group">
<label>Re-enter Password *</label>
<input name="confpass" type="password" class="form-control" placeholder="ReEnter Password" required>
</div>
<button type="submit" name="submit" class="btn btn-warning btn-lg">Sign Up</button>
</form>
</div>
</div>
</div>