forked from DarshanMaradiya/OnlineMusic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
166 lines (147 loc) · 3.81 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!DOCTYPE HTML>
<?php
$emailError = "";
?>
<html>
<head>
<title>Signup</title>
<!-- <link href='https://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet'>
<link rel="stylesheet" type="text/css" href="css.css"> -->
</head>
<body>
<div class="wrapper">
<h1>SIGN UP</h1>
<form method="post" action="signup.php">
<input class="name" placeholder="Name" type="text" name="name" required>
<div>
<p class="name-help">Please enter your first and last name.</p>
</div>
<input onblur="validateEmail()" id="mail" class="email" placeholder="Email" type="email" name="email" required>
<div>
<p class="email-help">Please enter your current email address.</p>
</div>
<input class="pass" placeholder="Password" type="password" name="password" required>
<div>
<p class="pass-help">Please enter your password.</p>
</div>
<input class="pass" onblur="matchPassword();" placeholder="Confirm password" type="password" name="confirmpass" required>
<div>
<p class="pass-help">Please confirm your password.</p>
</div>
<input class="submit" type="submit" name="submit" value="Sign Up" required><br>
</form>
</div>
<script type="text/javascript">
function validateEmail(){
var emailField = document.getElementById("mail");
emailField.value = emailField.value.trim();
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if (reg.test(emailField.value) == false)
{
alert("Enter valid email");
}
}
function matchPassword()
{
console.log("runned");
var pass = document.getElementsByClassName('pass');
// If Not same return False.
if (pass[0].value != pass[1].value) {
alert ("Passwords did not match!!\nConfirm again.");
pass[1].value = "";
}
}
</script>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
include('dbcon.php');
$qry = "SELECT `id` FROM `users`";
$run = mysqli_query($con, $qry);
$arr = array();
while($row = mysqli_fetch_array($run)){
array_push($arr, $row[0]);
}
sort($arr);
$i=1;
for($i=1; $i<=count($arr); $i++){
if($arr[$i-1]!=$i){
break;
}
}
$uname=strtolower($_POST['name']);
$email=$_POST['email'];
$passwd=md5($_POST['password']);
$allCorrect = true;
$qry = "SELECT * FROM `users` WHERE `name` = '$uname'";
$run = mysqli_query($con, $qry);
$row = mysqli_num_rows($run);
if($row > 0)
{
$allCorrect = false;
?>
<script type="text/javascript">
alert('Username already Exists!! try different one!');
window.history.go(-1);
</script>
<?php
}
$qry = "SELECT * FROM `users` WHERE `email` = '$email'";
$run = mysqli_query($con, $qry);
$row = mysqli_num_rows($run);
if($row > 0)
{
$allCorrect = false;
?>
<script type="text/javascript">
alert('Entered email-id is already registered!!');
window.history.go(-1);
</script>
<?php
}
if($allCorrect)
{
$qry = "INSERT INTO `users`(`id`, `name`, `password`, `email`) VALUES ('$i', '$uname', '$passwd', '$email')";
$run=mysqli_query($con,$qry);
if($run)
{
require('functions.php');
$sql = "SELECT * FROM `users` WHERE `email` = '$email'";
$runSql = mysqli_query($con, $sql);
$data = mysqli_fetch_assoc($runSql);
$success = verifyMail($data['id'], $data['email'], $data['name']);
if($success)
{
?>
<script>
alert('Record is Saved Successfully!\nWe have send a verification link to your Email.\nPlease verify your email address to avail more features!');
</script>
<?php
}
else{
?>
<script>
alert('Error sending mail');
</script>
<?php
}
?>
<script type="text/javascript">
window.history.go(-2);
</script>
<?php
}
else
{
?>
<script>
alert('Failed to save record');
</script>
<?php
}
}
}
?>