-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
239 lines (207 loc) · 9.27 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sign Up</title>
<link rel="stylesheet" type="text/css" href="stylesheet/signup.css"/>
<script type="text/javascript" src="scripts/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="scripts/effects.js"></script>
<script type="text/javascript" src="scripts/photo.js"></script>
<script type="text/javascript" src="scripts/search.js"></script>
</head>
<body>
<div class="help"></div>
<header>
<div class="HeaderTitle">
<img src="images/logo.png" width="70" height="70">
</div>
<nav>
<ul>
<li><a href="index.php">Sign In</a></li>
</ul>
</nav>
</header>
<hr>
<div class="notify">
<div class="notifytext"></div>
<div class="cross">X</div>
</div>
<div class="heading"><h1>User Registration</h1></div>
<?php
require 'scripts/connect.inc.php';
require 'scripts/mail.php';
if(isset($_POST['name']) && isset($_POST['username']) && isset($_POST['name']) && isset($_POST['age']) && isset($_POST['sex']) && isset($_POST['city']) && isset($_POST['email']) && isset($_POST['password']) && isset($_POST['confirmpassword']) && isset($_POST['sec_que']) && isset($_POST['answer']) ){
$name = strtolower(htmlentities($_POST['name']));
$username = htmlentities($_POST['username']);
$age = strtolower(htmlentities($_POST['age']));
$sex = strtolower(htmlentities($_POST['sex']));
$city = strtolower(htmlentities($_POST['city']));
$email = htmlentities($_POST['email']);
$password = htmlentities($_POST['password']);
$password_hash = md5($password);
$confirmpassword =htmlentities($_POST['confirmpassword']);
$sec_que = strtolower(htmlentities($_POST['sec_que']));
$answer = strtolower(htmlentities($_POST['answer']));
$filename = htmlentities($_FILES['file']['name']);
$size = $_FILES['file']['size'];
$type = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
$extension = strtolower(substr($filename, strpos($filename,'.')+1));
$max_size = 2097152;
$location = 'profiles/';
if(!empty($name) && !empty($username) && !empty($filename) && !empty($age) && !empty($sex) && !empty($city) && !empty($email) && !empty($password) && !empty($confirmpassword) && !empty($sec_que) && !empty($answer)){
$query_username = "SELECT * FROM `signup` WHERE `username` LIKE '".$username."'";
$query_username_run = mysql_query($query_username);
$query_username_num_rows = mysql_num_rows($query_username_run);
$query_email = "SELECT * FROM `signup` WHERE `email` LIKE '".$email."'";
$query_email_run = mysql_query($query_email);
$query_email_num_rows = mysql_num_rows($query_email_run);
if($query_username_num_rows == 1){
echo'<script type="text/javascript">
$(".notify").slideDown(1000);
$(".cross").click(function(e) {
$(".notify").slideUp(1000);
});
$(".notify > .notifytext").html("Username already chosen");
</script>';
}
else if($query_email_num_rows >=1){
echo'<script type="text/javascript">
$(".notify").slideDown(1000);
$(".cross").click(function(e) {
$(".notify").slideUp(1000);
});
$(".notify > .notifytext").html("Email Id already registered.");
</script>';
}
else if($password != $confirmpassword){
echo'<script type="text/javascript">
$(".notify").slideDown(1000);
$(".cross").click(function(e) {
$(".notify").slideUp(1000);
});
$(".notify > .notifytext").html("Password combination does not match.");
</script>';
}
else{
if(($extension =='jpg' || $extension == 'jpeg') && $size < $max_size && ($type=='image/jpg' || $type=='image/jpeg')){
move_uploaded_file($tmp_name,$location.$filename);
$extension = '.'.$extension;
rename($location.$filename,$location.$username.$extension);
$query = "INSERT INTO `mp`.`signup` (`id`, `username`, `password`, `name`, `email`, `age`, `sex`, `city`, `sec_que`, `sec_ans`, `photo`) VALUES (NULL, '".$username."', '".$password_hash."', '".$name."', '".$email."', '".$age."', '".$sex."', '".$city."', '".$sec_que."', '".$answer."', '".$location.$username.$extension."')";
if($query_run = mysql_query($query)){
//$msg = "congratulations!!! Your account has been successfully set with username "+$username+".\n Please use your email id and password to login.";
//$msg = wordwrap($msg,70);
//mail($email,"Thank you for signup",$msg
sendMail($email,$name,$username);
echo'<script type="text/javascript">
$(".notify").slideDown(1000);
$(\'form\').slideUp(1000);
$(".cross").click(function(e) {
$(".notify").slideUp(1000);
});
$(".notify > .notifytext").html("You\'ve successfully signed up.A mail has been sent to your mail id!! Click to go on <a href=\'index.php\'>login page</a>");
</script>';
}
}
else {
echo'<script type="text/javascript">
$(".notify").slideDown(1000);
$(\'form\').slideUp(1000);
$(".cross").click(function(e) {
$(".notify").slideUp(1000);
});
$(".notify > .notifytext").html("File should be less than 2 MB and JPEG/JPG");
</script>';
}
}
}
else {
echo'<script type="text/javascript">
$(".notify").slideDown(1000);
$(".cross").click(function(e) {
$(".notify").slideUp(1000);
});
$(".notify > .notifytext").html("Please fill all the fields.");
</script>';
}
}
?>
<form action="signup.php" method="POST" enctype="multipart/form-data">
<table border="0">
<tr>
<td>Your Name</td>
<td><input type="text" name="name" id="name" value="" class="FormElement" required></td>
</tr>
<tr>
<td>Choose a Username</td>
<td><input type="text" name="username" id="searchusername"class="FormElement" required></td>
</tr>
<tr>
<td>Upload Your photo</td>
<td><input type="file" name="file" id="photo" class="file_upload" onClick="imageDown();" onChange="readURL(this,'img_prev_Photo');" required></td>
</tr>
<tr>
<td></td>
<td><div id="imgDisplayPhoto" align='center' style="border: 1px solid;height:160px;width:120px;">
<img id="img_prev_Photo" src="images/profile.png" alt="select a image" border="0" style="height:160px;width:120px;">
</div> </td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="age" id="age" value="" class="FormElementAge" maxlength="3" required></td>
</tr>
<tr>
<td>Sex</td>
<td>
<select name="sex" id="sex" required>
<option value="male" selected >Male</option>
<option value="female">Female</option>
</select>
</td>
</tr>
<tr>
<td>City</td>
<td><select name="city" id="city" required>
<option value="delhi" >New Delhi</option>
<option value="jaipur" selected>Jaipur</option>
<option value="mumbai" >Mumbai</option>
<option value="kolkata" >Kolkata</option>
</select>
</td>
</tr>
<tr>
<td>E-Mail</td>
<td><input type="email" name="email" id="email" value="" class="FormElement" required></td>
</tr>
<tr>
<td>Enter New Password</td>
<td><input type="password" name="password" id="password" class="FormElement" maxlength="45" required></td>
</tr>
<tr>
<td>Confirm Password</td>
<td><input type="password" name="confirmpassword" class="FormElement" id="confirmpassword" maxlength="45" required></td>
</tr>
<tr>
<td>Secret Question</td>
<td><select name="sec_que" id="sec_que" required>
<option value="Which is your first school ?" >Which is your first school ?</option>
<option value="Who is your favourite teacher ?" selected>Who is your favourite teacher ?</option>
<option value="What is your pet name ?" >What is your pet name ?</option>
<option value="Where is your bith-place ?" >Where is your bith-place ?</option>
</select>
</td>
</tr>
<tr>
<td>Answer</td>
<td><input type="text" name="answer" class="FormElement" id="sec_ans" required></td>
</tr>
<tr>
<td>
<input type="submit" value="submit" class="button">
</td>
</tr>
</table>
</form>
</body>
</html>