-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignup.php
71 lines (53 loc) · 1.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
<?php
include_once('conn.php');
if($_SERVER['REQUEST_METHOD']=='POST'){
$email = $_POST['email'];
$name = $_POST['name'];
$password = $_POST['password'];
$confirmPassword = $_POST['confirmPassword'];
function validateCredentials($key,$data){
if(empty($data)){
header(`Location:http://localhost/auth/register?error=$key is empty`);
exit();
}
return;
}
function matchPassword($password,$confirmPassword){
if($password != $confirmPassword){
header(`Location:http://localhost/auth/register?error=password and confirm password does not match`);
exit();
}
return;
}
function checkUserExit($email){
global $db;
$query = "select * from user where email = '$email'";
$sql = mysqli_query($db,$query);
$rows = mysqli_num_rows($sql);
if($rows==1){
header("Location:http://localhost/auth/register.php?error=Email Already Exist");
exit();
}
return;
}
function registerUser($email,$name,$password,$confirmPassword){
global $db;
$query = "insert into user (email,name,password,confirmPassword) values('$email','$name','$password','$confirmPassword')";
$sql = mysqli_query($db,$query);
if($sql->error){
header("Location:http://localhost/auth/register?error=Please Try again");
exit();
}else{
header("Location:http://localhost/auth/login.php?message=User Successfully Registered");
exit();
}
}
validateCredentials("email",$email);
validateCredentials("password", $password);
validateCredentials("name", $name);
validateCredentials("confirmPassword", $confirmPassword);
matchPassword($password,$confirmPassword);
checkUserExit($email);
registerUser($email,$name,$password,$confirmPassword);
}
?>