-
Notifications
You must be signed in to change notification settings - Fork 0
/
signup.php
192 lines (183 loc) · 6.24 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
<!-- NOTE
SINGLE PAGE FORM ALONG WITH VALIDATION
NO PHP LEAKS BACK TO THE INDEX
-->
<?php
require_once("Includes/session.php");
$nameErr = $phoneErr = $addrErr = $emailErr = $passwordErr = $confpasswordErr = "";
$name = $email = $password = $confpassword = $address = "";
$flag=0;
//CHECK IF A VALID FORM STRING
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(isset($_POST["reg_submit"])) {
$email = test_input($_POST['email']);
$password = test_input($_POST["inputPassword"]);
$confpassword = test_input($_POST["confirmPassword"]);
$address = test_input($_POST["address"]);
$email = test_input($_POST['email']);
// NAME VALIDATION
if (empty($_POST["name"])) {
$nameErr = "Name is required";
$flag=1;
echo $nameErr;
} else {
$name = test_input($_POST["name"]);
// check if name only contains letters and whitespace
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
$nameErr = "Only letters and white space allowed";
$flag=1;
echo $nameErr;
}
}
// EMAIL VALIDATION
if (empty($_POST["email"])) {
$emailErr = "Email is required";
$flag=1;
} else {
$email = test_input($_POST["email"]);
// check if e-mail address is well-formed
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$emailErr = "Invalid email format";
$flag=1;
echo $emailErr;
}
}
// PASSWORD VALIDATION
if (empty($_POST["inputPassword"]))
{
$passwordErr = "PASSWORD missing";
$flag=1;
}
else
{
$password = $_POST["inputPassword"];
}
// CONFIRM PASSWORD
if (empty($_POST["confirmPassword"]))
{
$confpasswordErr = "missing";
$flag=1;
}
else
{
if($_POST['confirmPassword'] == $password)
{
$confpassword = $_POST["confirmPassword"];
}
else
{
$confpasswordErr = "Not same as password!";
$flag = 1;
}
}
// ADDRESS VALIDATION
if (empty($_POST["address"])) {
$addrErr = "Address is required";
$flag=1;
echo $addrErr;
} else {
$address = test_input($_POST["address"]);
// check if address only contains letters and whitespace
// if (!preg_match("/^[a-zA-Z1-9]*$/",$address)) {
// $addrErr = "Only letters, numbers and white space allowed";
// // $flag=1;
// echo $addrErr;
// }
}
//CONTACT VALIDATION
if (empty($_POST["contactNo"])) {
$flag=1;
$contactNo = "";
// echo "error here";
} else {
$contactNo = test_input($_POST["contactNo"]);
if(!preg_match("/^d{10}$/", $_POST["contactNo"])){
$phoneErr="10 digit phone no allowed.";
// $flag=1;
// echo "or here";
echo $_POST['contactNo'];
}
}
// Only if succeed from the validation thourough put
echo $flag;
if($flag == 0)
{
require_once("Includes/config.php");
$sql = "INSERT INTO user (`name`,`email`,`phone`,`pass`,`address`)
VALUES('$name','$email','$contactNo','$password','$address')";
echo $sql;
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
header("Location:index.php");
}
}
?>
<?php
// if(isset($flag)) {
// if($flag === 0) {
// echo '
// <table class="table">
// <tr class="success">Account Created</tr>
// </table>
// ';
// } elseif ($flag === 1) {
// echo '
// <table class="table">
// <tr class="danger">There were errors in the form.</tr>
// </table>
// ';
// }
// }
?>
<form action="signup.php" method="post" class="form-horizontal" role="form" onsubmit="return validateForm()">
<center>
<div class="row form-group">
<div class="col-md-12">
<input type="name" class="form-control" name="name" id="name" placeholder="Full Name" required>
<!-- <label><?php echo $nameErr;?></label> -->
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="email" class="form-control" name="email" id="email" placeholder="Email" required>
<!-- <label><?php echo $emailErr;?></label> -->
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="password" class="form-control" name="inputPassword" id="inputPassword" placeholder="Password" required>
<!-- <label><?php echo $passwordErr;?></label> -->
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="password" class="form-control" name="confirmPassword" placeholder="Confirm Password" required>
<!-- <label><?php echo $confpasswordErr;?></label><label><?php echo $confpasswordErr;?></label> -->
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="tel" class="form-control" name="contactNo" placeholder="Contact No." required>
<!-- <label><?php echo $phoneErr;?></label> -->
</div>
</div>
<div class="form-group">
<div class="col-md-12">
<input type="address" class="form-control" name="address" placeholder="Address" required>
<!-- <label><?php echo $addrErr;?></label> -->
</div>
</div>
<div class="form-group">
<div class="col-md-10">
<button name="reg_submit" class="btn btn-primary">Sign Up</button>
</div>
</div>
</center>
</form>