-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
137 lines (102 loc) · 3.17 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
<?php
session_start();
include("functions.php");
$con=mysqli_connect("localhost","root","","signup");
if(mysqli_connect_errno()){
echo"Error occured while connecting with database".mysqli_connect_errno();
}
if(logged_in()){
header("location:grocery.php");
exit(0);
}
$error="";
$success="";
if(isset($_POST['SignUp']))
{
$firstname=mysqli_real_escape_string($con,$_POST['fname']);
$lastname=mysqli_real_escape_string($con,$_POST['lname']);
$email=mysqli_real_escape_string($con,$_POST['email']);
$password=$_POST['password'];
$passwordconfirm=$_POST['passwordConfirm'];
$conditon=isset($_POST['terms']);
if(strlen($firstname)<3){
$error="Firstname is too short";
}
else if(strlen($firstname)>10){
$error="Firstname is too long";
}
else if(strlen($lastname)<3){
$error="Lastname is too short";
}
else if(strlen($lastname)>10){
$error="Lastname is too long";
}
else if(!filter_var($email,FILTER_VALIDATE_EMAIL)){
$error="Email is not valid";
}
else if(email_exists($email,$con)==TRUE){
$error="Email already Exists";
}
else if(strlen($password)<5){
$error="Password must be greator than 3 characters";
}
else if(strlen($password)>13){
$error="Password must be less than 13 characters";
}
else if($password!==$passwordconfirm){
$error="Password does not match";
}
else if(!$conditon)
{
$error="You must be agree to the T&C";
}
else{
$password=md5($password);
$passwordconfirm=md5($passwordconfirm);
$insertquery="INSERT INTO users(firstname,lastname,email,password,repassword) VALUES ('$firstname','$lastname','$email','$password','$passwordconfirm')";
if(mysqli_query($con,$insertquery)==TRUE){
$success="You are registered Successfully";
}
}
}
?>
<!DOCTYPE html>
<html>
<head> <title> Sign Up </title>
<link rel="stylesheet" href="styles.css"/>
</head>
<body>
<div id="wrapper">
<div id="formDiv">
<form method="POST" action="signup.php" enctype="multipart/form-data">
<label> First Name </label></br>
<input type="text" name="fname"/></br></br>
<label> Last Name </label></br>
<input type="text" name="lname" /> </br></br>
<label> Email </label></br>
<input type="text" name="email" /> </br></br>
<label>Password </label></br>
<input type="password" name="password"/> </br></br>
<label> Re-enter Password </label></br>
<input type="password" name="passwordConfirm"/> </br></br>
<input type="checkbox" name="terms"/>
<label> I agree with terms and conditions </label><br/><br/>
<input type="submit" name="SignUp" value="SignUp"/> </br></br>
</form>
<div id="error">
<?php
if($error==True){
echo "Error: ".$error;
}
if($success==True){
echo "Congrats, ".$success;
}
?>
</div>
</div>
<div id="menu">
<a href="login.php"> Login </a>
</div>
</div>
</body>
</html>