-
Notifications
You must be signed in to change notification settings - Fork 1
/
signup.php
93 lines (85 loc) · 2.77 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
<?php
session_start();
if($_POST){
$_SESSION['invalid'] = "";
if(!empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['password1']) && !empty($_POST['fname']) && !empty($_POST['lname']) && !empty($_POST['email']) && !empty($_POST['dob']) && !empty($_POST['age'])){
echo "here";
include('connection.php');
$user = $_POST['username'];
$pass = $_POST['password'];
$pass1 = $_POST['password1'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$age = $_POST['age'];
$flag = false;
$big = 0;
if(!preg_match("/^[a-zA-Z0-9]*$/",$username)){
$_SESSION['invalid'] .= "Username Should include digits and alphabets. ";
$big++;
}
if (!preg_match("/^[ A-Za-z ]+$/",$fname)) {
$_SESSION['invalid'] .= "Name should only have alphabets. ";
$big++;
}
if (!preg_match("/^[ A-Za-z ]+$/",$lname)) {
$_SESSION['invalid'] .= "Name should only have alphabets. ";
$big++;
}
if(!preg_match("/^[a-zA-Z0-9@!# ]*$/",$password)){
$_SESSION['invalid'] .= "Password Should include digits and alphabets and Special Characters(@!#). ";
$big++;
}
if(!preg_match("/^[a-zA-Z0-9@!# ]*$/",$password1)){
$_SESSION['invalid'] .= "Password Should include digits and alphabets and (@!#). ";
$big++;
}
if (!preg_match("/^[0-9]*$/",$age)) {
$_SESSION['invalid'] .="Age should be a valid number";
$big++;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$_SESSION['invalid'] .= "Invalid Email ID";
$big++;
}
if($big == 0){
if($pass != $pass1){
$flag = true;
$_SESSION['error_signup'] = "Passwords do not match";
header('location: index.php');
}
else{
$checkquery = "SELECT username FROM user WHERE username = '$user'";
$checkres = mysqli_query($conn,$checkquery);
if(mysqli_num_rows($checkres) > 0){
$_SESSION['error_signup'] = "User already exists";
header('location: index.php');
}
else{
$pass = md5($pass);
$query = "INSERT INTO user VALUES (null,'$email','$user','$pass','$dob',$age,'$fname','$lname')";
$res = mysqli_query($conn,$query);
$user_id = mysqli_insert_id($conn);
if($res){
echo "User added successfully";
$_SESSION['auth'] = true;
$_SESSION['user_id'] = $user_id;
$_SESSION['fname'] = $fname;
$_SESSION['lname'] = $lname;
header('location: app.php');
}
}
}
}
else{
header('location: index.php#account');
}
}
else{
$_SESSION['invalid'] = "Please fill all the fields";
echo "string";
header('location: index.php#account');
}
}
?>