-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
215 lines (189 loc) · 6.76 KB
/
signup.php
File metadata and controls
215 lines (189 loc) · 6.76 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
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
<?php require_once('inc/connection.php');?>
<?php
session_start();
//check the submit button has been pressed
if (isset($_POST['submit'])) {
$errors = array();
//check correct details has been entered
if(!isset($_POST['first_name']) || strlen(trim($_POST['first_name']))<1){
$errors[]= 'First Name is required/Invalid';
}
if(!isset($_POST['last_name']) || strlen(trim($_POST['last_name']))<1){
$errors[]= 'Last Name is required/Invalid';
}
if(!isset($_POST['tel_no']) || strlen(trim($_POST['tel_no']))<1){
$errors[]= 'Contact Details is required/Invalid';
}
if(!isset($_POST['address']) || strlen(trim($_POST['address']))<1){
$errors[]= 'Address is required/Invalid';
}
if(!isset($_POST['email']) || strlen(trim($_POST['email']))<1){
$errors[]= 'Email Address is required/Invalid';
}
if(!isset($_POST['password']) || strlen(trim($_POST['password']))<1){
$errors[]= 'Password is required/Invalid';
}
if(!strlen(trim($_POST['password'])<6))
{
$errors[]="Password must contain at least 6 characters!";
}
if(empty($errors)){
//get values in to variables
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$email=$_POST['email'];
$address=$_POST['address'];
$contact=$_POST['tel_no'];
$password=$_POST['password'];
$hashed_password=sha1($password);
$level=$_SESSION['level'];
$token= bin2hex(random_bytes(50));
if (isset($_POST['gender']) && $_POST['gender']=="male"){
$gender='Male';
}
if (isset($_POST['gender']) && $_POST['gender']=="female"){
$gender='Female';
}
//insert records into table
$Query ="INSERT INTO $level(first_name,last_name,email,password,gender,address,contact,level,token)VALUES ('{$first_name}','{$last_name}','{$email}','{$hashed_password}','{$gender}','{$address}','{$contact}','{$level}','{$token}')";
$result=mysqli_query($connection,$Query);
// if($result)
// {
// echo "one record added";
// }
// else
// {
// echo "database query failed";
// }
}
// else{
// print_r($errors);
// }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sign Up-Ceylon Trek</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/signup.css">
<link rel="stylesheet" href="css/top_bar.css">
<link rel="stylesheet" href="css/footer.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body style="background-image: url('img/ct3.jpg'); background-size:cover;background-position: center center;background-attachment: fixed; background-repeat:no-repeat;">
<?php include('inc/top_bar.php'); ?>
<div class="signup_box">
<form action="signup.php" method="post">
<h1>Sign Up</h1>
<?php
if (isset($_POST['submit'])) {
//check correct details has been entered
if(!isset($_POST['first_name']) || strlen(trim($_POST['first_name']))<1){
echo '<p class="error">First name is requried/Invalid!</p>';
}
if(!isset($_POST['last_name']) || strlen(trim($_POST['last_name']))<1){
echo '<p class="error">Last name is requried/Invalid!</p>';
}
if(!isset($_POST['tel_no']) || strlen(trim($_POST['tel_no']))<1){
echo '<p class="error">Contact Details is requried/Invalid!</p>';
}
if(!isset($_POST['address']) || strlen(trim($_POST['address']))<1){
echo '<p class="error">Address is requried/Invalid!</p>';
}
if(!isset($_POST['email']) || strlen(trim($_POST['email']))<1){
echo '<p class="error">Email Address is requried/Invalid!</p>';
}
if(!isset($_POST['password']) || strlen(trim($_POST['password']))<1){
echo '<p class="error">Password is requried/Invalid!</p>';
}
if((strlen(trim($_POST['password']))<6))
{
echo '<p class="error">Password must contain at least 6 characters!</p>';
}
}
?>
<div class="text_box">
<div>
<input class="input" type="text" name="first_name" placeholder="First Name">
</div>
</div><!-- text_box -->
<div class="text_box">
<div>
<input class="input" type="text" name="last_name" placeholder="Last Name">
</div>
</div><!-- text_box -->
<div class="text_box">
<div>
<input class="input" type="Phone" name="tel_no" placeholder="Contact Details">
</div>
</div><!-- text_box -->
<div class="text_box">
<div>
<input class="input" type="text" name="address" placeholder="Address">
</div>
</div><!-- text_box -->
<div class="text_box">
<div>
<input class="input" type="email" name="email" placeholder="Email Address">
</div>
</div><!-- text_box -->
<div>
<input class="input_radio" type="radio" name="gender" required="" value="male">
<label>Male</label>
</div><!-- label -->
<div>
<input class="input_radio" type="radio" name="gender" required="" value="female">
<label>Female</label>
</div><!-- label -->
<div class="text_box">
<div>
<input class="input" type="password" name="password" placeholder="Password" id="myInput1">
<span class="eye" onclick="myFunction1()">
<i id="hide1" class="fa fa-eye"></i>
<i id="hide2" class="fa fa-eye-slash"></i>
</span>
<script>
function myFunction1(){
var x=document.getElementById("myInput1");
var y=document.getElementById("hide1");
var z=document.getElementById("hide2");
if(x.type === "password"){
x.type ="text";
y.style.display = "block";
z.style.display = "none";
}
else{
x.type ="password";
y.style.display = "none";
z.style.display = "block";
}
}
</script>
</div>
</div><!-- text_box -->
<div class="check_signup">
<input type="checkbox" id="check" name="signup" required="">
<label for="check"> "I accept the Terms of Service "or" I accept the privacy statement" Click here the indicate that you have read and agree to the terms presented in the Terms and Conditions agreement.</label>
</div>
<button class="cancel" type="cancel" name="cancel">Cancel</button>
<button class="submit" type="submit" name="submit">Create Account</button>
<p>Already have an account? <a href="login.php">Log In</a></p>
</form>
<?php
if(isset($errors)&&empty($errors)){
function function_alert($message) {
// Display the alert box
echo "<script>alert('$message');</script>";
}
function_alert("Welcome to Ceylon Trek !");
}
?>
</div><!-- signup_box -->
<?php include('inc/footer.php'); ?>
</body>
<script type="text/javascript" src="js/jscript.js"></script>
</html>
<?php mysqli_close($connection);?>