-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
110 lines (91 loc) · 4.17 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php include 'includes/connection.php';?>
<?php include 'includes/header.php';?>
<?php include 'includes/navbar.php';?>
<?php
if (isset($_POST['signup'])) {
require "gump.class.php";
$gump = new GUMP();
$_POST = $gump->sanitize($_POST);
$gump->validation_rules(array(
'username' => 'required|alpha_numeric|max_len,20|min_len,4',
'name' => 'required|alpha_space|max_len,30|min_len,5',
'email' => 'required|valid_email',
'password' => 'required|max_len,50|min_len,6',
));
$gump->filter_rules(array(
'username' => 'trim|sanitize_string',
'name' => 'trim|sanitize_string',
'password' => 'trim',
'email' => 'trim|sanitize_email',
));
$validated_data = $gump->run($_POST);
if($validated_data === false) {
?>
<center><font color="red" > <?php echo $gump->get_readable_errors(true); ?> </font></center>
<?php
}
else if ($_POST['password'] !== $_POST['repassword'])
{
echo "<center><font color='red'>Passwords do not match </font></center>";
}
else {
$username = $validated_data['username'];
$checkusername = "SELECT * FROM users WHERE username = '$username'";
$run_check = mysqli_query($conn , $checkusername) or die(mysqli_error($conn));
$countusername = mysqli_num_rows($run_check);
if ($countusername > 0 ) {
echo "<center><font color='red'>Username is already taken! try a different one</font></center>";
}
$email = $validated_data['email'];
$checkemail = "SELECT * FROM users WHERE email = '$email'";
$run_check = mysqli_query($conn , $checkemail) or die(mysqli_error($conn));
$countemail = mysqli_num_rows($run_check);
if ($countemail > 0 ) {
echo "<center><font color='red'>Email is already taken! try a different one</font></center>";
}
else {
$name = $validated_data['name'];
$email = $validated_data['email'];
$pass = $validated_data['password'];
$password = crypt("$pass");
$role = $_POST['role'];
$query = "INSERT INTO users(username,name,email,password,role,token) VALUES ('$username' , '$name' , '$email', '$password' , '$role', '' )";
$result = mysqli_query($conn , $query) or die(mysqli_error($conn));
if (mysqli_affected_rows($conn) > 0) {
echo "<script>alert('SUCCESSFULLY REGISTERED');
window.location.href='login.php';</script>";
}
else {
echo "<script>alert('Error Occured');</script>";
}
}
}
}
?>
<br>
<html>
<body style="background-color:#009B77;">
<div class="container">
<div class="form">
<form id="contactform" method="POST">
<p class="contact"><label for="name">Name</label></p>
<input id="name" name="name" placeholder="First and last name" required="" tabindex="1" type="text" value="<?php if(isset($_POST['signup'])) { echo $_POST['name']; } ?>">
<p class="contact"><label for="email">Email</label></p>
<input id="email" name="email" placeholder="[email protected]" required="" type="email" value="<?php if(isset($_POST['signup'])) { echo $_POST['email']; } ?>">
<p class="contact"><label for="username">Create a username</label></p>
<input id="username" name="username" placeholder="username" required="" tabindex="2" type="text" value="<?php if(isset($_POST['signup'])) { echo $_POST['username']; } ?>">
<p class="contact"><label for="password">Create a password</label></p>
<input type="password" id="password" name="password" required="">
<p class="contact"><label for="repassword">Confirm your password</label></p>
<input type="password" id="repassword" name="repassword" required="">
<p class="contact"><label for="role">I am a..</label></p>
<select class="select-style gender" name="role">
<option value="teacher">Admin</option>
<option value="student">Customer</option>
</select><br><br>
<input class="buttom" name="signup" id="submit" tabindex="5" value="Sign me up!" type="submit">
</form>
</div>
</div>
</body>
</html>