-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup_database.php
More file actions
163 lines (132 loc) · 4.89 KB
/
signup_database.php
File metadata and controls
163 lines (132 loc) · 4.89 KB
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
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "root";
$dbname = "myDB";
function connect_db(){
$conn = mysqli_connect( $GLOBALS['dbhost'], $GLOBALS['dbuser'], $GLOBALS['dbpass'], $GLOBALS['dbname']);
if( mysqli_connect_errno($conn)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
return $conn;
}
function sanitizeString($var)
{
$var = strip_tags($var);
$var = htmlentities($var);
$var = stripslashes($var);
return ($var);
}
////////End of New Codes
$conn = connect_db();
//Check connection
if($conn -> connect_errno)
{
die("Connection failed: " . $conn ->connect_error);
}
//echo "Connected successfully";
//SignUp();
if(isset($_POST['submit']))
{
//echo "Congratualations!";
$first = sanitizeString($_POST['first_name']);
$last = sanitizeString($_POST['last_name']);
$name = sanitizeString($first.' '.$last);
$email = sanitizeString($_POST['email']);
$username = sanitizeString($_POST['username']);
$password = sanitizeString($_POST['pass']);
$repass = sanitizeString($_POST['repass']);
$year = sanitizeString($_POST['year']);
$month = sanitizeString($_POST['month']);
$day = sanitizeString($_POST['day']);
$dob = sanitizeString($year.'-'.$month.'-'.$day);
$gender = sanitizeString($_POST['gender']);
$verification_ques = sanitizeString($_POST['verification_question']);
$verification_ans = sanitizeString($_POST['verification_answer']);
$address = sanitizeString($_POST['address_name']);
$city = sanitizeString($_POST['city_name']);
$state = sanitizeString($_POST['state_name']);
$zipcode = sanitizeString($_POST['zip_code']);
$permanent_address = sanitizeString($address.','.$city.','.$state.' '.$zipcode);
if( (empty($first) || empty($last) || empty($email) || empty($username) || empty($password) || empty($repass) || empty($year) || empty($month) || empty($day) || empty($gender) || empty($verification_ques) || empty($verification_ans) || empty($address) || empty($city) || empty($state) || empty($zipcode) ) )
{
echo "Oops! Can't leave any field blank!";
}
else if ( ($password != $repass) )
{
echo "Password did not match! Please try again.";
echo "<br><a href='javascript:history.back()'>Go back to Sign Up Page</a>";
}
else
{
$password = sha1($password);
// >>>>>>>>>>>> MISSING PROFILE PIC<<<<<<<<<<<<<
// insert photo
$file_name = null;
if($_FILES["profile_pic"]["name"]){
$file_name = $_FILES["profile_pic"]["name"];
}
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["profile_pic"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["profile_pic"]["tmp_name"]);
if($check !== false) {
//echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
/*
if ($_FILES["profile_pic"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
*/
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["profile_pic"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["profile_pic"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
$sql = "INSERT INTO users(Username,Password,Name,email,dob,gender,verification_question,verification_answer,location, profile_pic ) VALUES ('$username','$password','$name','$email','$dob','$gender','$verification_ques','$verification_ans','$permanent_address','$file_name')";
$res = mysqli_query($conn,$sql);
if(!$res)
{
die("Query Failed! " . mysqli-error($conn));
}
else
{
echo ("Congratulations! you have successfully registered!");
echo "<br><a href='login.html'>Go To Login Page</a>";
}
}
echo "<br><a href='javascript:history.back()'>Go back to Sign Up Page</a>";
}
else
{
echo "Form not submitted properly!<br>";
echo "<a href='javascript:history.back()'>Go back to Sign Up Page</a>";
}
?>