-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsignup.php
More file actions
141 lines (128 loc) · 4.15 KB
/
signup.php
File metadata and controls
141 lines (128 loc) · 4.15 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
<?php
ob_start();
include('header.php');
include_once("db_connect.php");
session_start();
if(isset($_SESSION['user_id'])!="") {
header("Location: index.php");
}
if (isset($_POST['signup'])) {
//Escapes special characters in a string
$firstname = mysqli_real_escape_string($conn, $_POST['firstname']);
$lastname = mysqli_real_escape_string($conn, $_POST['lastname']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$password = mysqli_real_escape_string($conn, $_POST['password']);
$cpassword = mysqli_real_escape_string($conn, $_POST['cpassword']);
//check for non alphabets characters
if (!preg_match("/^[a-zA-Z ]+$/",$firstname)) {
$error = true;
$fname_error = "Name must contain only alphabets and space";
}
//check for non alphabets characters
if (!preg_match("/^[a-zA-Z ]+$/",$lastname)) {
$error = true;
$lname_error = "Name must contain only alphabets and space";
}
//Check if the variable $email is a valid email address
if(!filter_var($email,FILTER_VALIDATE_EMAIL)) {
$error = true;
$email_error = "Please Enter Valid Email ID";
}
//check to ensure Password is a minimum of 6 characters
if(strlen($password) < 6) {
$error = true;
$password_error = "Password must be minimum of 6 characters";
}
//check to make sure password fields match
if($password != $cpassword) {
$error = true;
$cpassword_error = "Password and Confirm Password doesn't match";
}
//check to ensure there are no errors
if (!$error) {
// create/insert account
if(mysqli_query($conn, "INSERT INTO users(firstname, lastname, email, password) VALUES('" . $firstname . "','" . $lastname . "','" . $email . "', '" . md5($password) . "')")) {
// direct to success page
header("Location:success.php");
exit();
} else {
$error_message = "Error in registering...Please try again later!";
}
}
}
?>
<head>
<link rel="stylesheet" href="css/style.css">
</head>
<div class="signup-page">
<div class="form">
<form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="signupform">
<fieldset>
<legend>Sign Up</legend>
<table>
<tr>
<div class="form-group">
<td>
<label for="firstname">First Name</label>
</td>
<td><input type="text" name="firstname" placeholder="Enter First Name" required value="<?php if($error) echo $firstname; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($fname_error)) echo $fname_error; ?></span>
</td>
</div>
</tr>
<tr>
<div class="form-group">
<td>
<label for="lastname">Last Name</label>
</td>
<td>
<input type="text" name="lastname" placeholder="Enter Last Name" required value="<?php if($error) echo $lastname; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($lname_error)) echo $lname_error; ?></span>
</td>
</div>
</tr>
<tr>
<div class="form-group">
<td>
<label for="email">Email</label>
</td>
<td>
<input type="text" name="email" placeholder="Enter Email" required value="<?php if($error) echo $email; ?>" class="form-control" />
<span class="text-danger"><?php if (isset($email_error)) echo $email_error; ?></span>
</td>
</div>
</tr>
<tr>
<div class="form-group">
<td>
<label for="password">Password</label>
</td>
<td>
<input type="password" name="password" placeholder="Enter Password" required class="form-control" />
<span class="text-danger"><?php if (isset($password_error)) echo $password_error; ?></span>
</td>
</div>
</tr>
<tr>
<div class="form-group">
<td>
<label for="password">Confirm Password</label>
</td>
<td>
<input type="password" name="cpassword" placeholder="Confirm Password" required class="form-control" />
<span class="text-danger"><?php if (isset($cpassword_error)) echo $cpassword_error; ?></span>
</td>
</div>
</tr>
<tr>
<div class="form-group">
<td>
<input type="submit" name="signup" value="Sign Up" class="btn btn-primary" />
</td>
</div>
</tr>
</table>
</fieldset>
</form>
</div>
</div>